christophe-hall / as3-commons

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

Wrong getDaysDiff() with days in different Daylight Saving Times #40

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
When doing relative date calculations, operations like addDays() and 
getDateDiff() often get used one after another. It is expected to have 
consistent dates/differences all the time, but run the following code snippet 
with the 0.3.2 version of as3-commons-lang:

var today:Date = new Date();
for (var i:int = 0; i < 300; i++) {
    var plusDate:Date = DateUtils.addDays(today, i);
    var plus:int = DateUtils.getDaysDiff(today, plusDate);

    var minusDate:Date = DateUtils.addDays(today, -i);
    var minus:int = DateUtils.getDaysDiff(today, minusDate);

    if (plus != i) {
        trace(i + ": Plus= " + plus + " [" + plusDate + "]");  
    } 
    if (minus != -i) {
        trace(i + ":  Minus=" + minus + " [" + minusDate + "]");  
    } 
}

When date1 and date2 are from different Daylight Saving Times, getDaysDiff() 
returns one day too many or too few (executed at 22:18:12 EST on 01/31/2011): 

41: Plus= 42 [Sun Mar 13 23:18:12 GMT-0400 2011]
42: Plus= 43 [Mon Mar 14 23:18:12 GMT-0400 2011]
...
86: Plus= 87 [Wed Apr 27 23:18:12 GMT-0400 2011]
86:  Minus=-85 [Sat Nov 6 23:18:12 GMT-0400 2010]

Compare with "correct" output inside the same DST:
40: Plus= 40 [Sat Mar 12 22:18:12 GMT-0500 2011]

That doesn't happen with 0.3.0 version.
Understood we have to agree, what adding a day means - always "24" hours or 
just a date change. And if time should be changed with the timezone offset 
change. In the example above if the today() time were 23:xx, adding 41 days 
would roll into next day, March 14, though days difference would still remain 
42... 

For my projects to not deal with that complexity, for date-only operations I've 
implemented Julian Day Number-based functions. 
Here is a good source of calendars info: 
http://www.tondering.dk/main/index.php/calendar-information
It'd be nice to have something like that implemented in as3-commons.

Original issue reported on code.google.com by akuzm...@gmail.com on 1 Feb 2011 at 3:44

GoogleCodeExporter commented 8 years ago

Original comment by mastakan...@gmail.com on 11 Sep 2011 at 6:29

GoogleCodeExporter commented 8 years ago

Original comment by martin.h...@gmail.com on 12 Sep 2011 at 6:14

GoogleCodeExporter commented 8 years ago
Maybe it could be simliar to this problem: 
http://bugs.adobe.com/jira/browse/SDK-31544

Original comment by achim.r...@gmail.com on 15 Sep 2011 at 3:04