3 Replies Latest reply on Dec 22, 2006 8:28 AM by kglad

    Bug with Date

    firehawk2002
      While working on a project I've ran across a pretty nasty bug with the Date class in flash. I've tested this in 8.0 Professional and the issue also exists in 9.0 Alpha Release.

      var d1:Date = new Date(2006, 12, 21);
      var d2:Date = new Date(2007, 1, 31);
      trace(Math.floor((d2.getTime() - d1.getTime()))/ 86400000);

      This bit of code will trace 42 days which is correct.

      Now try this:

      var d1:Date = new Date(2006, 12, 21);
      var d2:Date = new Date(2007, 2, 1);
      trace(Math.floor((d2.getTime() - d1.getTime()))/ 86400000);

      It traces out 39.

      So how can a day one day later be 3 days less? Nice eh?

      I further tested

      var d1:Date = new Date(2006, 12, 21);
      var d2:Date = new Date(2007, 12, 21);
      trace(Math.floor((d2.getTime() - d1.getTime()))/ 86400000);

      Which traces 365 and is correct. It appears there is some time frame in Febuary, I haven't defined the range that has problems.