Example #1
0
// Full roundtrip for 1601-01-01 to 2400-12-31
// checks sequence of rata die numbers and validates date output
// (since the input is all nominal days of the calendar in that range
// and the result of the inverse calculation must match the input no
// invalid output can occur.)
void test_RoundTripDate() {
    struct calendar truDate, expDate = { 1600, 0, 12, 31 };;
    int32	 truRdn, expRdn	= ntpcal_date_to_rd(&expDate);
    int	 leaps;

    while (expDate.year < 2400) {
        expDate.year++;
        expDate.month	= 0;
        expDate.yearday = 0;
        leaps = leapdays(expDate.year);
        while (expDate.month < 12) {
            expDate.month++;
            expDate.monthday = 0;
            while (expDate.monthday < real_month_days[leaps][expDate.month]) {
                expDate.monthday++;
                expDate.yearday++;
                expRdn++;

                truRdn = ntpcal_date_to_rd(&expDate);
                TEST_ASSERT_EQUAL(expRdn, truRdn);

                ntpcal_rd_to_date(&truDate, truRdn);
                TEST_ASSERT_TRUE(IsEqualDateCal(expDate, truDate));
            }
        }
    }
}
Example #2
0
// Full roundtrip for 1601-01-01 to 2400-12-31
// checks sequence of rata die numbers and validates date output
// (since the input is all nominal days of the calendar in that range
// and the result of the inverse calculation must match the input no
// invalid output can occur.)
TEST_F(calendarTest, RoundTripDate) {
	calendar truDate, expDate = { 1600, 0, 12, 31 };;
	int32	 truRdn, expRdn	= ntpcal_date_to_rd(&expDate);
	int	 leaps;

	while (expDate.year < 2400) {
		expDate.year++;
		expDate.month	= 0;
		expDate.yearday = 0;
		leaps = leapdays(expDate.year);
		while (expDate.month < 12) {
			expDate.month++;			
			expDate.monthday = 0;
			while (expDate.monthday < real_month_days[leaps][expDate.month]) {
				expDate.monthday++;
				expDate.yearday++;
				expRdn++;

				truRdn = ntpcal_date_to_rd(&expDate);
				EXPECT_EQ(expRdn, truRdn);

				ntpcal_rd_to_date(&truDate, truRdn);
				EXPECT_TRUE(IsEqualDate(expDate, truDate));
			}
		}
	}
}
Example #3
0
uint32_t
caltontp(
	const struct calendar *jt
	)
{
	int32_t eraday;	/* CE Rata Die number	*/
	vint64  ntptime;/* resulting NTP time	*/

	NTP_INSIST(jt != NULL);

	NTP_REQUIRE(jt->month <= 13);	/* permit month 0..13! */
	NTP_REQUIRE(jt->monthday <= 32);
	NTP_REQUIRE(jt->yearday <= 366);
	NTP_REQUIRE(jt->hour <= 24);
	NTP_REQUIRE(jt->minute <= MINSPERHR);
	NTP_REQUIRE(jt->second <= SECSPERMIN);

	/*
	 * First convert the date to he corresponding RataDie
	 * number. If yearday is not zero, assume that it contains a
	 * useable value and avoid all calculations involving month
	 * and day-of-month. Do a full evaluation otherwise.
	 */
	if (jt->yearday)
		eraday = ntpcal_year_to_ystart(jt->year)
		       + jt->yearday - 1;
	else
		eraday = ntpcal_date_to_rd(jt);

	ntptime = ntpcal_dayjoin(eraday - DAY_NTP_STARTS,
				 ntpcal_etime_to_seconds(jt->hour, jt->minute,
							 jt->second));
	return ntptime.d_s.lo;
}
Example #4
0
// check first day of march for first 10000 years
void test_LeapYears2() {
    struct calendar dateIn, dateOut;

    for (dateIn.year = 1; dateIn.year < 10000; ++dateIn.year) {
        dateIn.month	= 3;
        dateIn.monthday = 1;
        dateIn.yearday	= 60 + leapdays(dateIn.year);

        ntpcal_rd_to_date(&dateOut, ntpcal_date_to_rd(&dateIn));
        TEST_ASSERT_TRUE(IsEqualDateCal(dateIn, dateOut));
    }
}
Example #5
0
// check first day of march for first 10000 years
TEST_F(calendarTest, LeapYears2) {
	calendar dateIn, dateOut;

	for (dateIn.year = 1; dateIn.year < 10000; ++dateIn.year) {
		dateIn.month	= 3;
		dateIn.monthday = 1;
		dateIn.yearday	= 60 + leapdays(dateIn.year);

		ntpcal_rd_to_date(&dateOut, ntpcal_date_to_rd(&dateIn));
		EXPECT_TRUE(IsEqualDate(dateIn, dateOut));
	}
}
Example #6
0
/* check last day of february for first 10000 years */
void
test_LeapYears1(void)
{
	struct calendar dateIn, dateOut;

	for (dateIn.year = 1; dateIn.year < 10000; ++dateIn.year) {
		dateIn.month	= 2;
		dateIn.monthday = 28 + leapdays(dateIn.year);
		dateIn.yearday	= 31 + dateIn.monthday;

		ntpcal_rd_to_date(&dateOut, ntpcal_date_to_rd(&dateIn));

		TEST_ASSERT_TRUE(IsEqualDateCal(&dateIn, &dateOut));
	}

	return;
}