示例#1
0
/* test the day/sec join & split ops, making sure that 32bit
 * intermediate results would definitely overflow and the hi DWORD of
 * the 'vint64' is definitely needed.
 */
void
test_DaySplitMerge(void)
{
	int32 day,sec;

	for (day = -1000000; day <= 1000000; day += 100) {
		for (sec = -100000; sec <= 186400; sec += 10000) {
			vint64		 merge;
			ntpcal_split split;
			int32		 eday;
			int32		 esec;

			merge = ntpcal_dayjoin(day, sec);
			split = ntpcal_daysplit(&merge);
			eday  = day;
			esec  = sec;

			while (esec >= 86400) {
				eday += 1;
				esec -= 86400;
			}
			while (esec < 0) {
				eday -= 1;
				esec += 86400;
			}

			TEST_ASSERT_EQUAL(eday, split.hi);
			TEST_ASSERT_EQUAL(esec, split.lo);
		}
	}

	return;
}
示例#2
0
/*
 * 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;
}
示例#3
0
static int32
ntp_to_year(
	u_int32 ntp)
{
	vint64	     t;
	ntpcal_split s;

	t = ntpcal_ntp_to_ntp(ntp, NULL);
	s = ntpcal_daysplit(&t);
	s = ntpcal_split_eradays(s.hi + DAY_NTP_STARTS - 1, NULL);
	return s.hi + 1;
}
示例#4
0
/* ------------------------------------------------------------------ */
int32_t
leapsec_daystolive(
	uint32_t       when,
	const time_t * tpiv)
{
	const leap_table_t * pt;
	vint64 limit;

	pt = leapsec_get_table(FALSE);
	limit = ntpcal_ntp_to_ntp(when, tpiv);
	limit = subv64(&pt->head.expire, &limit);
	return ntpcal_daysplit(&limit).hi;
}
示例#5
0
/* ------------------------------------------------------------------ */
int32_t
leapsec_daystolive(
	uint32_t       when,
	const time_t * tpiv)
{
	const leap_table_t * pt;
	time64_t limit;

	pt = leapsec_get_table(false);
	limit = ntpcal_ntp_to_ntp(when, tpiv);
	limit = pt->head.expire - limit;
	return ntpcal_daysplit(limit).hi;
}
示例#6
0
/*
 * 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);
}
示例#7
0
void
caljulian(
	uint32_t		ntp,
	struct calendar *	jt
	)
{
	vint64		vlong;
	ntpcal_split	split;
	
	
	NTP_INSIST(NULL != jt);

	/*
	 * Unfold ntp time around current time into NTP domain. Split
	 * into days and seconds, shift days into CE domain and
	 * process the parts.
	 */
	vlong = ntpcal_ntp_to_ntp(ntp, NULL);
	split = ntpcal_daysplit(&vlong);
	ntpcal_daysplit_to_date(jt, &split, DAY_NTP_STARTS);
}
示例#8
0
文件: calendar.cpp 项目: benjit89/ntp
// test the day/sec join & split ops, making sure that 32bit
// intermediate results would definitely overflow and the hi DWORD of
// the 'vint64' is definitely needed.
TEST_F(calendarTest, DaySplitMerge) {
	for (int32 day = -1000000; day <= 1000000; day += 100) {
		for (int32 sec = -100000; sec <= 186400; sec += 10000) {
			vint64	     merge = ntpcal_dayjoin(day, sec);
			ntpcal_split split = ntpcal_daysplit(&merge);
			int32	     eday  = day;
			int32	     esec  = sec;

			while (esec >= 86400) {
				eday += 1;
				esec -= 86400;
			}
			while (esec < 0) {
				eday -= 1;
				esec += 86400;
			}

			EXPECT_EQ(eday, split.hi);
			EXPECT_EQ(esec, split.lo);
		}
	}
}