Example #1
0
void test_NoWrapInDateRangeLeapYear(void) {
	const u_int32 input = 3549528000UL; // 2012-06-24 12:00:00
	const u_int32 expected = 3534364800UL; // 2012-01-01 00:00:00

	TEST_ASSERT_EQUAL(expected, calyearstart(input, &nowtime));
	TEST_ASSERT_EQUAL(expected, calyearstart(input, NULL));
}
Example #2
0
void test_WrapInDateRange(void) {
	const u_int32 input = 19904UL; // 2036-02-07 12:00:00
	const u_int32 expected = 4291747200UL; // 2036-01-01 00:00:00

	TEST_ASSERT_EQUAL(expected, calyearstart(input, &nowtime));
	TEST_ASSERT_EQUAL(expected, calyearstart(input, NULL));
}
Example #3
0
void test_NoWrapInDateRange(void) {
	const u_int32 input = 3486372600UL; // 2010-06-24 12:50:00.
	const u_int32 expected = 3471292800UL; // 2010-01-01 00:00:00

	TEST_ASSERT_EQUAL(expected, calyearstart(input, &nowtime));
	TEST_ASSERT_EQUAL(expected, calyearstart(input, NULL));
}
Example #4
0
TEST_F(calyearstartTest, WrapInDateRange) {
	const u_int32 input = 19904UL; // 2036-02-07 12:00:00
	const u_int32 expected = 4291747200UL; // 2036-01-01 00:00:00

	EXPECT_EQ(expected, calyearstart(input, &nowtime));
	EXPECT_EQ(expected, calyearstart(input, NULL));
}
Example #5
0
TEST_F(calyearstartTest, NoWrapInDateRangeLeapYear) {
	const u_int32 input = 3549528000UL; // 2012-06-24 12:00:00
	const u_int32 expected = 3534364800UL; // 2012-01-01 00:00:00

	EXPECT_EQ(expected, calyearstart(input, &nowtime));
	EXPECT_EQ(expected, calyearstart(input, NULL));
}
Example #6
0
TEST_F(calyearstartTest, NoWrapInDateRange) {
	const u_int32 input = 3486372600UL; // 2010-06-24 12:50:00.
	const u_int32 expected = 3471292800UL; // 2010-01-01 00:00:00

	EXPECT_EQ(expected, calyearstart(input, &nowtime));
	EXPECT_EQ(expected, calyearstart(input, NULL));
}
Example #7
0
// Roundtrip testing on calyearstart
void test_RoundTripYearStart() {
    static const time_t pivot = 0;
    u_int32 ntp, expys, truys;
    struct calendar date;

    for (ntp = 0; ntp < 0xFFFFFFFFu - 30000000u; ntp += 30000000u) {
        truys = calyearstart(ntp, &pivot);
        ntpcal_ntp_to_date(&date, ntp, &pivot);
        date.month = date.monthday = 1;
        date.hour = date.minute = date.second = 0;
        expys = ntpcal_date_to_ntp(&date);
        TEST_ASSERT_EQUAL(expys, truys);
    }
}
Example #8
0
// Roundtrip testing on calyearstart
TEST_F(calendarTest, RoundTripYearStart) {
	static const time_t pivot = 0;
	u_int32 ntp, expys, truys;
	calendar date;

	for (ntp = 0; ntp < 0xFFFFFFFFu - 30000000u; ntp += 30000000u) {
		truys = calyearstart(ntp, &pivot);
		ntpcal_ntp_to_date(&date, ntp, &pivot);
		date.month = date.monthday = 1;
		date.hour = date.minute = date.second = 0;
		expys = ntpcal_date_to_ntp(&date);
		EXPECT_EQ(expys, truys);
	}
}	
Example #9
0
int
clocktime(
	int yday,
	int hour,
	int minute,
	int second,
	int tzoff,
	u_long rec_ui,
	u_long *yearstart,
	u_int32 *ts_ui
	)
{
	register long tmp;
	register u_long date;
	register u_long yst;

	/*
	 * Compute the offset into the year in seconds.  Note that
	 * this could come out to be a negative number.
	 */
	tmp = (long)(MULBY24((yday-1)) + hour + tzoff);
	tmp = MULBY60(tmp) + (long)minute;
	tmp = MULBY60(tmp) + (long)second;

	/*
	 * Initialize yearstart, if necessary.
	 */
	yst = *yearstart;
	if (yst == 0) {
		yst = calyearstart(rec_ui);
		*yearstart = yst;
	}

	/*
	 * Now the fun begins.  We demand that the received clock time
	 * be within CLOSETIME of the receive timestamp, but
	 * there is uncertainty about the year the timestamp is in.
	 * Use the current year start for the first check, this should
	 * work most of the time.
	 */
	date = (u_long)(tmp + (long)yst);
	if (date < (rec_ui + CLOSETIME) &&
	    date > (rec_ui - CLOSETIME)) {
		*ts_ui = date;
		return 1;
	}

	/*
	 * Trouble.  Next check is to see if the year rolled over and, if
	 * so, try again with the new year's start.
	 */
	yst = calyearstart(rec_ui);
	if (yst != *yearstart) {
		date = (u_long)((long)yst + tmp);
		*ts_ui = date;
		if (date < (rec_ui + CLOSETIME) &&
		    date > (rec_ui - CLOSETIME)) {
			*yearstart = yst;
			return 1;
		}
	}

	/*
	 * Here we know the year start matches the current system
	 * time.  One remaining possibility is that the time code
	 * is in the year previous to that of the system time.  This
	 * is only worth checking if the receive timestamp is less
	 * than a couple of days into the new year.
	 */
	if ((rec_ui - yst) < TWODAYS) {
		yst = calyearstart(yst - TWODAYS);
		if (yst != *yearstart) {
			date = (u_long)(tmp + (long)yst);
			if (date < (rec_ui + CLOSETIME) &&
			    date > (rec_ui - CLOSETIME)) {
				*yearstart = yst;
				*ts_ui = date;
				return 1;
			}
		}
	}

	/*
	 * One last possibility is that the time stamp is in the year
	 * following the year the system is in.  Try this one before
	 * giving up.
	 */
	yst = calyearstart(rec_ui + TWODAYS);
	if (yst != *yearstart) {
		date = (u_long)((long)yst + tmp);
		if (date < (rec_ui + CLOSETIME) &&
		    date > (rec_ui - CLOSETIME)) {
			*yearstart = yst;
			*ts_ui = date;
			return 1;
		}
	}

	/*
	 * Give it up.
	 */
	return 0;
}