Annotation of coherent/g/usr/lib/misc/jdtotm.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Julian date to year, month, mday, hour, min, sec, yday, wday fields
        !             3:  * Algorithm from Duffett-Smith, Practical Astronomy With Your Calculator
        !             4:  * Also Meeus, Astronomical Formulae for Calculators
        !             5:  */
        !             6: #include "local_misc.h"
        !             7: tm_t *
        !             8: jday_to_tm(jd)
        !             9: jday_t jd;
        !            10: {
        !            11:        register tm_t *tp;
        !            12:        register long d, s, A, B, F;
        !            13:        static tm_t t;
        !            14: 
        !            15:        tp = &t;
        !            16:        d = jd.j_d;
        !            17:        s = jd.j_s;
        !            18:        if ((s += 86400L/2) >= 86400L) {
        !            19:                s -= 86400L; d += 1;
        !            20:        }
        !            21:        tp->tm_isdst = 0;               /* no telling who stepped here */
        !            22:        tp->tm_wday = (d+1) % 7;
        !            23:        if ((A = d) > 2299160L) {
        !            24:                A = (d*100 - 186721625L) / 3652425L;
        !            25:                A = d + 1 + A - (A / 4);
        !            26:        }
        !            27:        B = A + 1524;
        !            28:        tp->tm_year = (B*100 - 12210) / 36525L;
        !            29:        B -= (tp->tm_year * 36525L) / 100;
        !            30:        tp->tm_mon = (B * 10000) / 306001L;
        !            31:        F = (306001L * tp->tm_mon) / 10000;
        !            32:        tp->tm_mday = B - F;
        !            33:        tp->tm_yday = B - (tp->tm_mon >= 14 ? 428+1 : 61+2+1);
        !            34:        tp->tm_mon -= tp->tm_mon > 13 ? 13 : 1;
        !            35:        tp->tm_year -= tp->tm_mon > 2 ? 4716 :  4715;
        !            36:        if (tp->tm_mon > 2 && isleapyear(tp->tm_year))
        !            37:                ++tp->tm_yday;
        !            38:        tp->tm_sec = s % 60;
        !            39:        s /= 60;
        !            40:        tp->tm_min = (unsigned int)s % 60;
        !            41:        tp->tm_hour = (unsigned int)s / 60;
        !            42:        /* Correct for tm_t bias */
        !            43:        tp->tm_year -= 1900;
        !            44:        tp->tm_mon -= 1;
        !            45:        return tp;
        !            46: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.