What are the default values taken (say 1721119) to calculate the Gregorian Year, Month, Day from Julian Day [closed]

天大地大妈咪最大 提交于 2019-12-25 18:33:14

问题


Lot and lot of thanks in advance !

The following code snippet is a function that gives me Year, Month and Day for a given Julian Day..

Can you please tell me what does the constants here signify. I can find this code all over the net but nobody explains about the default values taken here. Also if anyone can explain what the function will do.

Suppose, the value i am passing for JD is 2456447..

VOID GetGregorianDate(LONG JD, PWORD Year, PWORD Month, PWORD Day)
{
    LONG j, y, d, m;
    j = JD - 1721119;            //what is this value - 1721119 (may be related to day.. but how ?)
    y = (4 * j - 1) / 146097;    //what is this value - 146097 (may be related to year.. but how ?)
    j = 4 * j - 1 - 146097 * y;
    d = j / 4;
    j = (4 * d + 3) / 1461;        // ?
    d = 4 * d + 3 - 1461 * j;
    d = (d + 4) / 4;
    m = (5 * d - 3) / 153;        // ?
    d = 5 * d - 3 - 153 * m;
    d = (d + 5) / 5;
    y = 100 * y + j;
    if (m < 10)
    {
        m = m + 3;
    }
    else 
    {
        m = m - 9;
        y = y + 1;
    }

    *Year   = (WORD) y;
    *Month  = (WORD) m;
    *Day    = (WORD) d;
}

回答1:


They're just artifacts of the Gregorian calendar and the arbitrary date chosen as the start of the Julian epoch.

  • 1721119 is the offset from JD 0 to the start of March 1BC (since there was no 0AD); subtracting this gives the number of days since then. March is chosen as the "start" of a year so that leap days come at the "end", which makes the arithmetic simpler.
  • 146097 is the number of days in four centuries, which is the time it takes for the cycle of leap years to repeat.
  • 1461 is the number of days in four years (the short leap-year cycle).
  • 153 is the number of days in 5 consecutive months alternating between 31 and 30 days (either Mar-Jul or Aug-Dec).
  • The various additions and subtractions of 3 and 9 are to restore the "start" of the year to January.

The fiddly arithmetic puts them all together to give the correct count of days, taking into account leap years and varying month lengths.

This paper (referenced from Wikipedia) describes how the various magic numbers in the inverse calculation (Gregorian date to Julian day) arise; the numbers in your algorithm arise in a similar way.



来源:https://stackoverflow.com/questions/16896311/what-are-the-default-values-taken-say-1721119-to-calculate-the-gregorian-year

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!