Efficient algorithm for converting number of days to years (including leap years)

后端 未结 10 1994
逝去的感伤
逝去的感伤 2021-02-05 17:04

The problem

I am writing a class for holding dates in c++, and I found the following problem:

I have a number of days N since a reference date (in

10条回答
  •  长发绾君心
    2021-02-05 17:36

    I have a number of days N since a reference date (in my case that would be Jan 1, 0001 AD)...

    In that case, "efficiency" in applying the 4-100-400 rule and looking up month lengths is not your main problem. Please be also aware of the multiple problems inherent in applying today's Gregorian calendar to dates predating its inception, and the fact that Gregorian was not introduced uniformly. (*)

    Wikipedia is a good starting point to a very involved subject.

    (*): Depending on country, anywhere between 15 October 1582 and 15 February 1923, resp. not at all, actually.

提交回复
热议问题