[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: ntpsec as server questions



On Thu, Dec 07, 2023 at 11:19:19PM -0500, gene heskett wrote:
> Of minor interest to me, not once in the above link does it credit the K&R
> Manual for C, which has a method for determining leap years.

The what now?  Leap years are defined by the Gregorian Calendar, as
declared in the 16th century, long before K&R.

https://en.wikipedia.org/wiki/Gregorian_calendar

  The rule for leap years is:

    Every year that is exactly divisible by four is a leap year, except
    for years that are exactly divisible by 100, but these centurial years
    are leap years if they are exactly divisible by 400. For example, the
    years 1700, 1800, and 1900 are not leap years, but the year 2000 is.

    — United States Naval Observatory[2]

I don't have my copy of K&R close to hand, but my preferred implementation
for a function that decides leap years is (pseudo-code):

bool isleapyear (int year) {
    if (year % 400 == 0) return true;
    if (year % 100 == 0) return false;
    if (year % 4 == 0) return true;
    return false;
}

Why would you expect a time zone database to acknowledge one
implementation of a simple Gregorian leap year function?


Reply to: