diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2014-12-02 09:01:21 +0000 |
---|---|---|
committer | <> | 2014-12-04 16:11:25 +0000 |
commit | bdab5265fcbf3f472545073a23f8999749a9f2b9 (patch) | |
tree | c6018dd03dea906f8f1fb5f105f05b71a7dc250a /libntp/calyearstart.c | |
download | ntp-d4b7cd9723cce9561fa15f74b90b85a3a61b5ef8.tar.gz |
Imported from /home/lorry/working-area/delta_ntp/ntp-dev-4.2.7p482.tar.gz.ntp-dev-4.2.7p482
Diffstat (limited to 'libntp/calyearstart.c')
-rw-r--r-- | libntp/calyearstart.c | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/libntp/calyearstart.c b/libntp/calyearstart.c new file mode 100644 index 0000000..9e3f58f --- /dev/null +++ b/libntp/calyearstart.c @@ -0,0 +1,88 @@ +/* + * calyearstart - determine the NTP time at midnight of January 1 in + * the year of the given date. + */ +#include <config.h> +#include <sys/types.h> + +#include "ntp_types.h" +#include "ntp_calendar.h" +#include "ntp_stdlib.h" +#include "ntp_assert.h" + +/* + * Juergen Perlinger, 2010-05-02 + * + * Redone in terms of the calendar functions. It's rather simple: + * - expand the NTP time stamp + * - split into days and seconds since midnight, dropping the partial day + * - get full number of days before year start in NTP epoch + * - convert to seconds, truncated to 32 bits. + */ +u_int32 +calyearstart(u_int32 ntptime, const time_t *pivot) +{ + u_int32 ndays; /* elapsed days since NTP starts */ + vint64 vlong; + ntpcal_split split; + + vlong = ntpcal_ntp_to_ntp(ntptime, pivot); + split = ntpcal_daysplit(&vlong); + ndays = ntpcal_rd_to_ystart(split.hi + DAY_NTP_STARTS) + - DAY_NTP_STARTS; + + return (u_int32)(ndays * SECSPERDAY); +} + +/* + * calmonthstart - get NTP time at midnight of the first day of the + * current month. + */ +u_int32 +calmonthstart(u_int32 ntptime, const time_t *pivot) +{ + u_int32 ndays; /* elapsed days since NTP starts */ + vint64 vlong; + ntpcal_split split; + + vlong = ntpcal_ntp_to_ntp(ntptime, pivot); + split = ntpcal_daysplit(&vlong); + ndays = ntpcal_rd_to_mstart(split.hi + DAY_NTP_STARTS) + - DAY_NTP_STARTS; + + return (u_int32)(ndays * SECSPERDAY); +} + +/* + * calweekstart - get NTP time at midnight of the last monday on or + * before the current date. + */ +u_int32 +calweekstart(u_int32 ntptime, const time_t *pivot) +{ + u_int32 ndays; /* elapsed days since NTP starts */ + vint64 vlong; + ntpcal_split split; + + vlong = ntpcal_ntp_to_ntp(ntptime, pivot); + split = ntpcal_daysplit(&vlong); + ndays = ntpcal_weekday_le(split.hi + DAY_NTP_STARTS, CAL_MONDAY) + - DAY_NTP_STARTS; + + return (u_int32)(ndays * SECSPERDAY); +} + +/* + * caldaystart - get NTP time at midnight of the current day. + */ +u_int32 +caldaystart(u_int32 ntptime, const time_t *pivot) +{ + vint64 vlong; + ntpcal_split split; + + vlong = ntpcal_ntp_to_ntp(ntptime, pivot); + split = ntpcal_daysplit(&vlong); + + return ntptime - split.lo; +} |