diff options
Diffstat (limited to 'src/datetime.c')
-rw-r--r-- | src/datetime.c | 56 |
1 files changed, 40 insertions, 16 deletions
diff --git a/src/datetime.c b/src/datetime.c index 3db5f7f..5f5d9bf 100644 --- a/src/datetime.c +++ b/src/datetime.c @@ -1,7 +1,7 @@ /* 19950925 */ #include "datetime.h" -void datetime_tai(struct datetime *dt,datetime_sec t) +void datetime_tai(struct datetime *dt, datetime_sec t) { int day; int tod; @@ -9,43 +9,67 @@ void datetime_tai(struct datetime *dt,datetime_sec t) int yday; int wday; int mon; - + tod = t % 86400; day = t / 86400; - if (tod < 0) { tod += 86400; --day; } - + if (tod < 0) { + tod += 86400; + --day; + } + dt->hour = tod / 3600; tod %= 3600; dt->min = tod / 60; dt->sec = tod % 60; - - wday = (day + 4) % 7; if (wday < 0) wday += 7; + + wday = (day + 4) % 7; + if (wday < 0) wday += 7; dt->wday = wday; - + day -= 11017; /* day 0 is march 1, 2000 */ year = 5 + day / 146097; - day = day % 146097; if (day < 0) { day += 146097; --year; } + day = day % 146097; + if (day < 0) { + day += 146097; + --year; + } /* from now on, day is nonnegative */ year *= 4; - if (day == 146096) { year += 3; day = 36524; } - else { year += day / 36524; day %= 36524; } + if (day == 146096) { + year += 3; + day = 36524; + } else { + year += day / 36524; + day %= 36524; + } year *= 25; year += day / 1461; day %= 1461; year *= 4; yday = (day < 306); - if (day == 1460) { year += 3; day = 365; } - else { year += day / 365; day %= 365; } + if (day == 1460) { + year += 3; + day = 365; + } else { + year += day / 365; + day %= 365; + } yday += day; - + day *= 10; mon = (day + 5) / 306; day = day + 5 - 306 * mon; day /= 10; - if (mon >= 10) { yday -= 306; ++year; mon -= 10; } - else { yday += 59; mon += 2; } - + if (mon >= 10) { + yday -= 306; + ++year; + mon -= 10; + } else { + yday += 59; + mon += 2; + } + dt->yday = yday; dt->year = year - 1900; dt->mon = mon; |