Open GoogleCodeExporter opened 8 years ago
This algorithm from minix source seems to work fine:
http://www.raspberryginger.com/jbailey/minix/html/gmtime_8c-source.html
Original comment by mayhem...@hotmail.no
on 5 Feb 2011 at 9:37
Sorry for referring to that Minix-algorithm. Forget that. It doesn't work at
all for dates before 1970. (1969 becomes 2105) :-|
Original comment by mayhem...@hotmail.no
on 5 Feb 2011 at 10:31
Proposed fix also added as comment on issue 495 :
The problem seems not to have been "+1" on line #113: "res->tm_mday = days +
1;",
but the use of the _ISLEAP(y) macro on lines #91 and #103.
"y" on these lines are the full years (i.e: 1999,2000,2001 etc), while the
macro is converted to expect y-1900 (i.e: 99,100,101)
_ISLEAP(2000) returns 0
_ISLEAP(100) returns 1
So that 2000 is concidered NOT to be a leap-year, while it actually is.
Therefore in the original code all split_time()-calls for dates after
29.Feb.2000 gets wrong, while in the current code (with no +1), all dates
before 1.March 2000 gets wrong instead.
I think the fix should be:
line #91: yleap = _ISLEAP(y-1900);
line #103: yleap = _ISLEAP(y-1900);
line #113: res->tm_mday = days + 1; // as originally
(Don't change the _ISLEAP-macro, because it is also used by _DAYS_IN_YEAR(year)
macro, but then with "short-years" (i.e: 99,100,101))
Original comment by royandre...@gmail.com
on 17 Nov 2011 at 8:49
Original issue reported on code.google.com by
mayhem...@hotmail.no
on 5 Feb 2011 at 6:41