1
#include <gtest/gtest.h>
3
#include <drizzled/calendar.h>
5
using namespace drizzled;
7
TEST(calendar_julian_day_number_from_gregorian_date_test, CalculationTest)
9
uint32_t year, month, day;
11
year= 2010; month= 4; day= 2;
12
EXPECT_EQ(2455289, julian_day_number_from_gregorian_date(year, month, day));
14
year= 1976; month= 12; day= 21;
15
EXPECT_EQ(2443134, julian_day_number_from_gregorian_date(year, month, day));
17
year= 2050; month= 6; day= 15;
18
EXPECT_EQ(2469973, julian_day_number_from_gregorian_date(year, month, day));
20
year= 1999; month= 12; day= 31;
21
EXPECT_EQ(2451544, julian_day_number_from_gregorian_date(year, month, day));
23
year= 2008; month= 2; day= 29;
24
EXPECT_EQ(2454526, julian_day_number_from_gregorian_date(year, month, day));
27
TEST(calendar_gregorian_date_from_julian_day_number_test, CalculationTest)
30
uint32_t year_out, month_out, day_out;
33
gregorian_date_from_julian_day_number(julian_day, &year_out, &month_out, &day_out);
34
EXPECT_TRUE((year_out == 2010) && (month_out == 4) && (day_out == 2));
37
gregorian_date_from_julian_day_number(julian_day, &year_out, &month_out, &day_out);
38
EXPECT_TRUE((year_out == 1976) && (month_out == 12) && (day_out == 21));
41
gregorian_date_from_julian_day_number(julian_day, &year_out, &month_out, &day_out);
42
EXPECT_TRUE((year_out == 2050) && (month_out == 6) && (day_out == 15));
45
gregorian_date_from_julian_day_number(julian_day, &year_out, &month_out, &day_out);
46
EXPECT_TRUE((year_out == 1999) && (month_out == 12) && (day_out == 31));
49
gregorian_date_from_julian_day_number(julian_day, &year_out, &month_out, &day_out);
50
EXPECT_TRUE((year_out == 2008) && (month_out == 2) && (day_out == 29));
56
TEST(calendar_day_of_week_test, MondayFirst)
58
/* Friday 2010 IV 2 */
59
ASSERT_EQ(4, day_of_week(2455289, false));
62
TEST(calendar_day_of_week_test, SundayFirst)
64
/* Friday 2010 IV 2 */
65
ASSERT_EQ(5, day_of_week(2455289, true));
71
TEST(calendar_in_unix_epoch_range_test, MinOfRange)
73
uint32_t year= 1970, month= 1, day= 1, hour= 0, minute= 0, second= 0;
75
ASSERT_TRUE(in_unix_epoch_range(year, month, day, hour, minute, second));
78
TEST(calendar_in_unix_epoch_range_test, MaxOfRange)
80
uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 7;
82
ASSERT_TRUE(in_unix_epoch_range(year, month, day, hour, minute, second));
85
TEST(calendar_in_unix_epoch_range_test, OneSecondBeforeMinOfRange)
87
uint32_t year= 1969, month= 12, day= 31, hour= 23, minute= 59, second= 59;
89
ASSERT_FALSE(in_unix_epoch_range(year, month, day, hour, minute, second));
92
TEST(calendar_in_unix_epoch_range_test, OneSecondAfterMaxOfRange)
94
uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 8;
96
ASSERT_FALSE(in_unix_epoch_range(year, month, day, hour, minute, second));
99
TEST(calendar_in_unix_epoch_range_test, InsideRange)
101
uint32_t year= 1980, month= 11, day= 1, hour= 5, minute= 8, second= 5;
102
EXPECT_TRUE(in_unix_epoch_range(year, month, day, hour, minute, second));
104
year= 2010; month= 4; day= 2; hour= 21; minute= 44; second= 0;
105
EXPECT_TRUE(in_unix_epoch_range(year, month, day, hour, minute, second));
107
year= 2020; month= 7; day= 13; hour= 16; minute= 56; second= 59;
108
EXPECT_TRUE(in_unix_epoch_range(year, month, day, hour, minute, second));