hroptatyr/dateutils — Issue #3: leap year calculation
Author: akaldenhoven
Created: 2011-10-26 09:45:55+00:00
State: open

Hello everybody,

hroptatyr, thanks for the great work on dateutils. I am playing around with it for a few minutes now and I like it already...;-)

Although, I think I found a bug that should be squished, the determination whether a year is a leap year or not.

If you run the following line from bash:

for i in {2000..2100}; do echo dadd $i-02-28 1d; done | bash

you will get the next day after each 28th of february for every year in the range from 2000 to 2100.

What I see from this, is that your code determines that a year is a leap year if it is evenly divisible by the number 4.

As far as I know, this is not the correct definition of a leap year.

To find out whether a year is a leap year sequentially follow the following steps:

0) precondition: the year is in the Gregorian calendar which started October 15, 1582
1) if the year is is evenly divisible by 4, it IS a leap year
2) if the year is is evenly divisible by 100, it IS NOT a leap year (although it is evenly divisible by 4)
3) if the year is is evenly divisible by 400, it IS a leap year (although it is evenly divisible by 100)

Here are some sources to check this:
http://en.wikipedia.org/wiki/Gregorian_calendar
http://en.wikipedia.org/wiki/Leap_year

Kind regards,
André Kaldenhoven