1999-12-09 13:01:21 +00:00
|
|
|
/*
|
|
|
|
* calyearstart - determine the NTP time at midnight of January 1 in
|
|
|
|
* the year of the given date.
|
|
|
|
*/
|
2014-12-20 22:52:39 +00:00
|
|
|
#include <config.h>
|
1999-12-09 13:01:21 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include "ntp_types.h"
|
|
|
|
#include "ntp_calendar.h"
|
|
|
|
#include "ntp_stdlib.h"
|
2013-12-04 21:33:17 +00:00
|
|
|
#include "ntp_assert.h"
|
1999-12-09 13:01:21 +00:00
|
|
|
|
2013-12-04 21:33:17 +00:00
|
|
|
/*
|
2014-12-20 22:52:39 +00:00
|
|
|
* 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.
|
2013-12-04 21:33:17 +00:00
|
|
|
*/
|
2014-12-20 22:52:39 +00:00
|
|
|
u_int32
|
|
|
|
calyearstart(u_int32 ntptime, const time_t *pivot)
|
1999-12-09 13:01:21 +00:00
|
|
|
{
|
2014-12-20 22:52:39 +00:00
|
|
|
u_int32 ndays; /* elapsed days since NTP starts */
|
|
|
|
vint64 vlong;
|
|
|
|
ntpcal_split split;
|
2013-12-04 21:33:17 +00:00
|
|
|
|
2014-12-20 22:52:39 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2019-03-07 13:01:16 +00:00
|
|
|
* calweekstart - get NTP time at midnight of the last Monday on or
|
2014-12-20 22:52:39 +00:00
|
|
|
* 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);
|
2013-12-04 21:33:17 +00:00
|
|
|
|
2014-12-20 22:52:39 +00:00
|
|
|
return ntptime - split.lo;
|
1999-12-09 13:01:21 +00:00
|
|
|
}
|