dizag / as3-commons

Automatically exported from code.google.com/p/as3-commons
1 stars 0 forks source link

DateUtils.getDaysDiff incorrect on DST boundaries #27

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The following fails:

var start:Date = new Date(2010, 10, 7);
var end:Date = new Date(2010, 10, 8);
Assert.assertEquals(1, DateUtils.getDaysDiff(start, end));

A patch to fix this would be to substitute the getDaysDiff function with:

var startMillis:Number = startDate.getTime();
var endMillis:Number = endDate.getTime();
var dstOffset:Number = (startDate.getTimezoneOffset() - 
endDate.getTimezoneOffset()) * MILLIS_PER_MINUTE;
return Math.ceil((endMillis - startMillis + dstOffset)/ MILLIS_PER_DAY);

Original issue reported on code.google.com by babin...@gmail.com on 16 Aug 2010 at 5:55

GoogleCodeExporter commented 9 years ago

Original comment by jamesghandour on 17 Aug 2010 at 1:28

GoogleCodeExporter commented 9 years ago

Original comment by jamesghandour on 17 Aug 2010 at 2:02

GoogleCodeExporter commented 9 years ago
Why so complicated? date.valueOf() should work faster/better.

Original comment by mastakan...@gmail.com on 17 Aug 2010 at 10:07