|
|
1.1 ! root 1: /* ! 2: * Year, month, day to julian day in integers. ! 3: * Algorithm from Duffett-Smith, Practical Astronomy With Your Calculator ! 4: * Also Meeus, Astronomical Formulae for Calculators ! 5: */ ! 6: #include "local_misc.h" ! 7: ! 8: /* Pack year, month, and day into long package for easy compares */ ! 9: #define pymd(y,m,d) (((long)(y)<<16)|((m)<<8)|(d)) ! 10: ! 11: jday_t ! 12: tm_to_jday(tp) ! 13: register tm_t *tp; ! 14: { ! 15: register int y, m, B; ! 16: register long C, D; ! 17: jday_t jd; ! 18: ! 19: y = tp->tm_year + 1900; ! 20: m = tp->tm_mon + 1; ! 21: if (m <= 2) { ! 22: y -= 1; m += 12; ! 23: } ! 24: /* Gregorian correction */ ! 25: if (pymd(y, m, tp->tm_mday) > pymd(1582, 10, 15)) { ! 26: B = 2 - (y/100) + (y/400); ! 27: } else ! 28: B = 0; ! 29: C = (y * 36525L) / 100; ! 30: D = ((m + 1) * 306001L) / 10000; ! 31: jd.j_d = tp->tm_mday + B + C + D + 1720994L; ! 32: jd.j_s = tp->tm_sec + 60L * (tp->tm_min + 60 * tp->tm_hour); ! 33: if ((jd.j_s += 86400L/2) >= 86400L) { ! 34: jd.j_s -= 86400L; jd.j_d += 1; ! 35: } ! 36: return jd; ! 37: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.