2 * calyearstart - determine the NTP time at midnight of January 1 in
3 * the year of the given date.
9 #include "ntp_calendar.h"
10 #include "ntp_stdlib.h"
11 #include "ntp_assert.h"
14 * Juergen Perlinger, 2010-05-02
16 * Redone in terms of the calendar functions. It's rather simple:
17 * - expand the NTP time stamp
18 * - split into days and seconds since midnight, dropping the partial day
19 * - get full number of days before year start in NTP epoch
20 * - convert to seconds, truncated to 32 bits.
23 calyearstart(u_int32 ntptime, const time_t *pivot)
25 u_int32 ndays; /* elapsed days since NTP starts */
29 vlong = ntpcal_ntp_to_ntp(ntptime, pivot);
30 split = ntpcal_daysplit(&vlong);
31 ndays = ntpcal_rd_to_ystart(split.hi + DAY_NTP_STARTS)
34 return (u_int32)(ndays * SECSPERDAY);
38 * calmonthstart - get NTP time at midnight of the first day of the
42 calmonthstart(u_int32 ntptime, const time_t *pivot)
44 u_int32 ndays; /* elapsed days since NTP starts */
48 vlong = ntpcal_ntp_to_ntp(ntptime, pivot);
49 split = ntpcal_daysplit(&vlong);
50 ndays = ntpcal_rd_to_mstart(split.hi + DAY_NTP_STARTS)
53 return (u_int32)(ndays * SECSPERDAY);
57 * calweekstart - get NTP time at midnight of the last monday on or
58 * before the current date.
61 calweekstart(u_int32 ntptime, const time_t *pivot)
63 u_int32 ndays; /* elapsed days since NTP starts */
67 vlong = ntpcal_ntp_to_ntp(ntptime, pivot);
68 split = ntpcal_daysplit(&vlong);
69 ndays = ntpcal_weekday_le(split.hi + DAY_NTP_STARTS, CAL_MONDAY)
72 return (u_int32)(ndays * SECSPERDAY);
76 * caldaystart - get NTP time at midnight of the current day.
79 caldaystart(u_int32 ntptime, const time_t *pivot)
84 vlong = ntpcal_ntp_to_ntp(ntptime, pivot);
85 split = ntpcal_daysplit(&vlong);
87 return ntptime - split.lo;