21 #include <type_traits> 23 #include "gtest/gtest.h" 26 namespace time_internal {
32 std::string
Format(
const T& t) {
40 #if __cpp_constexpr >= 201304 || (defined(_MSC_VER) && _MSC_VER >= 1910) 43 TEST(CivilTime, Normal) {
45 static_assert(css.second() == 12,
"Normal.second");
47 static_assert(cmm.minute() == 14,
"Normal.minute");
49 static_assert(chh.hour() == 17,
"Normal.hour");
51 static_assert(cd.day() == 28,
"Normal.day");
53 static_assert(cm.month() == 1,
"Normal.month");
55 static_assert(cy.year() == 2016,
"Normal.year");
58 TEST(CivilTime, Conversion) {
60 static_assert(cy.year() == 2016,
"Conversion.year");
62 static_assert(cm.month() == 1,
"Conversion.month");
64 static_assert(cd.day() == 1,
"Conversion.day");
66 static_assert(chh.hour() == 0,
"Conversion.hour");
68 static_assert(cmm.minute() == 0,
"Conversion.minute");
70 static_assert(css.second() == 0,
"Conversion.second");
75 TEST(CivilTime, Normalized) {
77 static_assert(cs.year() == 2016,
"Normalized.year");
78 static_assert(cs.month() == 1,
"Normalized.month");
79 static_assert(cs.day() == 28,
"Normalized.day");
80 static_assert(cs.hour() == 17,
"Normalized.hour");
81 static_assert(cs.minute() == 14,
"Normalized.minute");
82 static_assert(cs.second() == 12,
"Normalized.second");
85 TEST(CivilTime, SecondOverflow) {
87 static_assert(cs.year() == 2016,
"SecondOverflow.year");
88 static_assert(cs.month() == 1,
"SecondOverflow.month");
89 static_assert(cs.day() == 28,
"SecondOverflow.day");
90 static_assert(cs.hour() == 17,
"SecondOverflow.hour");
91 static_assert(cs.minute() == 16,
"SecondOverflow.minute");
92 static_assert(cs.second() == 1,
"SecondOverflow.second");
95 TEST(CivilTime, SecondUnderflow) {
97 static_assert(cs.year() == 2016,
"SecondUnderflow.year");
98 static_assert(cs.month() == 1,
"SecondUnderflow.month");
99 static_assert(cs.day() == 28,
"SecondUnderflow.day");
100 static_assert(cs.hour() == 17,
"SecondUnderflow.hour");
101 static_assert(cs.minute() == 11,
"SecondUnderflow.minute");
102 static_assert(cs.second() == 59,
"SecondUnderflow.second");
105 TEST(CivilTime, MinuteOverflow) {
107 static_assert(cs.year() == 2016,
"MinuteOverflow.year");
108 static_assert(cs.month() == 1,
"MinuteOverflow.month");
109 static_assert(cs.day() == 28,
"MinuteOverflow.day");
110 static_assert(cs.hour() == 19,
"MinuteOverflow.hour");
111 static_assert(cs.minute() == 1,
"MinuteOverflow.minute");
112 static_assert(cs.second() == 12,
"MinuteOverflow.second");
115 TEST(CivilTime, MinuteUnderflow) {
117 static_assert(cs.year() == 2016,
"MinuteUnderflow.year");
118 static_assert(cs.month() == 1,
"MinuteUnderflow.month");
119 static_assert(cs.day() == 28,
"MinuteUnderflow.day");
120 static_assert(cs.hour() == 14,
"MinuteUnderflow.hour");
121 static_assert(cs.minute() == 59,
"MinuteUnderflow.minute");
122 static_assert(cs.second() == 12,
"MinuteUnderflow.second");
125 TEST(CivilTime, HourOverflow) {
127 static_assert(cs.year() == 2016,
"HourOverflow.year");
128 static_assert(cs.month() == 1,
"HourOverflow.month");
129 static_assert(cs.day() == 30,
"HourOverflow.day");
130 static_assert(cs.hour() == 1,
"HourOverflow.hour");
131 static_assert(cs.minute() == 14,
"HourOverflow.minute");
132 static_assert(cs.second() == 12,
"HourOverflow.second");
135 TEST(CivilTime, HourUnderflow) {
137 static_assert(cs.year() == 2016,
"HourUnderflow.year");
138 static_assert(cs.month() == 1,
"HourUnderflow.month");
139 static_assert(cs.day() == 25,
"HourUnderflow.day");
140 static_assert(cs.hour() == 23,
"HourUnderflow.hour");
141 static_assert(cs.minute() == 14,
"HourUnderflow.minute");
142 static_assert(cs.second() == 12,
"HourUnderflow.second");
145 TEST(CivilTime, MonthOverflow) {
147 static_assert(cs.year() == 2018,
"MonthOverflow.year");
148 static_assert(cs.month() == 1,
"MonthOverflow.month");
149 static_assert(cs.day() == 28,
"MonthOverflow.day");
150 static_assert(cs.hour() == 17,
"MonthOverflow.hour");
151 static_assert(cs.minute() == 14,
"MonthOverflow.minute");
152 static_assert(cs.second() == 12,
"MonthOverflow.second");
155 TEST(CivilTime, MonthUnderflow) {
157 static_assert(cs.year() == 2013,
"MonthUnderflow.year");
158 static_assert(cs.month() == 11,
"MonthUnderflow.month");
159 static_assert(cs.day() == 28,
"MonthUnderflow.day");
160 static_assert(cs.hour() == 17,
"MonthUnderflow.hour");
161 static_assert(cs.minute() == 14,
"MonthUnderflow.minute");
162 static_assert(cs.second() == 12,
"MonthUnderflow.second");
165 TEST(CivilTime, C4Overflow) {
167 static_assert(cs.year() == 2816,
"C4Overflow.year");
168 static_assert(cs.month() == 1,
"C4Overflow.month");
169 static_assert(cs.day() == 1,
"C4Overflow.day");
170 static_assert(cs.hour() == 17,
"C4Overflow.hour");
171 static_assert(cs.minute() == 14,
"C4Overflow.minute");
172 static_assert(cs.second() == 12,
"C4Overflow.second");
175 TEST(CivilTime, C4Underflow) {
176 constexpr
civil_second cs(2016, 1, -292195, 17, 14, 12);
177 static_assert(cs.year() == 1215,
"C4Underflow.year");
178 static_assert(cs.month() == 12,
"C4Underflow.month");
179 static_assert(cs.day() == 30,
"C4Underflow.day");
180 static_assert(cs.hour() == 17,
"C4Underflow.hour");
181 static_assert(cs.minute() == 14,
"C4Underflow.minute");
182 static_assert(cs.second() == 12,
"C4Underflow.second");
185 TEST(CivilTime, MixedNormalization) {
186 constexpr
civil_second cs(2016, -42, 122, 99, -147, 4949);
187 static_assert(cs.year() == 2012,
"MixedNormalization.year");
188 static_assert(cs.month() == 10,
"MixedNormalization.month");
189 static_assert(cs.day() == 4,
"MixedNormalization.day");
190 static_assert(cs.hour() == 1,
"MixedNormalization.hour");
191 static_assert(cs.minute() == 55,
"MixedNormalization.minute");
192 static_assert(cs.second() == 29,
"MixedNormalization.second");
197 TEST(CivilTime, Less) {
200 constexpr
bool less = cs1 < cs2;
201 static_assert(less,
"Less");
206 TEST(CivilTime, Addition) {
209 static_assert(cs2.year() == 2016,
"Addition.year");
210 static_assert(cs2.month() == 1,
"Addition.month");
211 static_assert(cs2.day() == 28,
"Addition.day");
212 static_assert(cs2.hour() == 17,
"Addition.hour");
213 static_assert(cs2.minute() == 15,
"Addition.minute");
214 static_assert(cs2.second() == 2,
"Addition.second");
217 TEST(CivilTime, Subtraction) {
220 static_assert(cs2.year() == 2016,
"Subtraction.year");
221 static_assert(cs2.month() == 1,
"Subtraction.month");
222 static_assert(cs2.day() == 28,
"Subtraction.day");
223 static_assert(cs2.hour() == 17,
"Subtraction.hour");
224 static_assert(cs2.minute() == 13,
"Subtraction.minute");
225 static_assert(cs2.second() == 22,
"Subtraction.second");
228 TEST(CivilTime, Difference) {
231 constexpr
int diff = cd1 - cd2;
232 static_assert(diff == 365,
"Difference");
236 TEST(CivilTime, DifferenceWithHugeYear) {
238 constexpr
civil_day d1(9223372036854775807, 1, 1);
239 constexpr
civil_day d2(9223372036854775807, 12, 31);
240 static_assert(d2 - d1 == 364,
"DifferenceWithHugeYear");
243 constexpr
civil_day d1(-9223372036854775807 - 1, 1, 1);
244 constexpr
civil_day d2(-9223372036854775807 - 1, 12, 31);
245 static_assert(d2 - d1 == 365,
"DifferenceWithHugeYear");
249 constexpr
civil_day d1(9223372036854775807, 1, 1);
250 constexpr
civil_day d2(9198119301927009252, 6, 6);
251 static_assert(d1 - d2 == 9223372036854775807,
"DifferenceWithHugeYear");
252 static_assert((d2 - 1) - d1 == -9223372036854775807 - 1,
253 "DifferenceWithHugeYear");
257 constexpr
civil_day d1(-9223372036854775807 - 1, 1, 1);
258 constexpr
civil_day d2(-9198119301927009254, 7, 28);
259 static_assert(d2 - d1 == 9223372036854775807,
"DifferenceWithHugeYear");
260 static_assert(d1 - (d2 + 1) == -9223372036854775807 - 1,
261 "DifferenceWithHugeYear");
265 constexpr
civil_day d1(-12626367463883278, 9, 3);
266 constexpr
civil_day d2(12626367463883277, 3, 28);
267 static_assert(d2 - d1 == 9223372036854775807,
"DifferenceWithHugeYear");
268 static_assert(d1 - (d2 + 1) == -9223372036854775807 - 1,
269 "DifferenceWithHugeYear");
274 TEST(CivilTime, DifferenceNoIntermediateOverflow) {
278 constexpr
civil_second s1(-292277022657, 1, 27, 8, 29 - 1, 52);
280 static_assert(s1 - s2 == -9223372036854775807 - 1,
281 "DifferenceNoIntermediateOverflow");
286 constexpr
civil_second s1(292277026596, 12, 4, 15, 30, 7 - 7);
288 static_assert(s1 - s2 == 9223372036854775807,
289 "DifferenceNoIntermediateOverflow");
295 TEST(CivilTime, WeekDay) {
298 static_assert(wd == weekday::thursday,
"Weekday");
301 TEST(CivilTime, NextWeekDay) {
304 static_assert(next.year() == 2016,
"NextWeekDay.year");
305 static_assert(next.month() == 2,
"NextWeekDay.month");
306 static_assert(next.day() == 4,
"NextWeekDay.day");
309 TEST(CivilTime, PrevWeekDay) {
312 static_assert(prev.year() == 2016,
"PrevWeekDay.year");
313 static_assert(prev.month() == 1,
"PrevWeekDay.month");
314 static_assert(prev.day() == 21,
"PrevWeekDay.day");
317 TEST(CivilTime, YearDay) {
320 static_assert(yd == 28,
"YearDay");
322 #endif // __cpp_constexpr >= 201304 || (defined(_MSC_VER) && _MSC_VER >= 1910) 326 TEST(CivilTime, DefaultConstruction) {
328 EXPECT_EQ(
"1970-01-01T00:00:00",
Format(ss));
331 EXPECT_EQ(
"1970-01-01T00:00",
Format(mm));
334 EXPECT_EQ(
"1970-01-01T00",
Format(hh));
337 EXPECT_EQ(
"1970-01-01",
Format(d));
340 EXPECT_EQ(
"1970-01",
Format(m));
343 EXPECT_EQ(
"1970",
Format(y));
346 TEST(CivilTime, StructMember) {
354 TEST(CivilTime, FieldsConstruction) {
398 TEST(CivilTime, FieldsConstructionLimits) {
399 const int kIntMax = std::numeric_limits<int>::max();
400 EXPECT_EQ(
"2038-01-19T03:14:07",
402 EXPECT_EQ(
"6121-02-11T05:21:07",
404 EXPECT_EQ(
"251104-11-20T12:21:07",
406 EXPECT_EQ(
"6130715-05-30T12:21:07",
409 "185087685-11-26T12:21:07",
412 const int kIntMin = std::numeric_limits<int>::min();
413 EXPECT_EQ(
"1901-12-13T20:45:52",
415 EXPECT_EQ(
"-2182-11-20T18:37:52",
417 EXPECT_EQ(
"-247165-02-11T10:37:52",
419 EXPECT_EQ(
"-6126776-08-01T10:37:52",
422 "-185083747-10-31T10:37:52",
426 TEST(CivilTime, ImplicitCrossAlignment) {
435 EXPECT_EQ(second, year);
437 EXPECT_EQ(second, month);
439 EXPECT_EQ(second, day);
441 EXPECT_EQ(second, hour);
443 EXPECT_EQ(second, minute);
446 EXPECT_EQ(minute, year);
448 EXPECT_EQ(minute, month);
450 EXPECT_EQ(minute, day);
452 EXPECT_EQ(minute, hour);
455 EXPECT_EQ(hour, year);
457 EXPECT_EQ(hour, month);
459 EXPECT_EQ(hour, day);
462 EXPECT_EQ(day, year);
464 EXPECT_EQ(day, month);
467 EXPECT_EQ(month, year);
491 TEST(CivilTime, ExplicitCrossAlignment) {
497 EXPECT_EQ(
"2015-01-02T03:04:05",
Format(second));
500 EXPECT_EQ(
"2015-01-02T03:04",
Format(minute));
503 EXPECT_EQ(
"2015-01-02T03",
Format(hour));
506 EXPECT_EQ(
"2015-01-02",
Format(day));
509 EXPECT_EQ(
"2015-01",
Format(month));
512 EXPECT_EQ(
"2015",
Format(year));
519 EXPECT_EQ(
"2015-01",
Format(month));
522 EXPECT_EQ(
"2015-01-01",
Format(day));
525 EXPECT_EQ(
"2015-01-01T00",
Format(hour));
528 EXPECT_EQ(
"2015-01-01T00:00",
Format(minute));
531 EXPECT_EQ(
"2015-01-01T00:00:00",
Format(second));
535 template <
typename T1,
typename T2>
537 template <
typename U1,
typename U2>
538 static std::false_type test(...);
539 template <
typename U1,
typename U2>
540 static std::true_type test(decltype(std::declval<U1>() - std::declval<U2>()));
541 static constexpr
bool value = decltype(test<T1, T2>(0))::value;
544 TEST(CivilTime, DisallowCrossAlignedDifference) {
575 TEST(CivilTime, ValueSemantics) {
581 EXPECT_EQ(
"2015-01-02T03",
Format(d));
588 EXPECT_EQ(year, month);
590 #define TEST_RELATIONAL(OLDER, YOUNGER) \ 592 EXPECT_FALSE(OLDER < OLDER); \ 593 EXPECT_FALSE(OLDER > OLDER); \ 594 EXPECT_TRUE(OLDER >= OLDER); \ 595 EXPECT_TRUE(OLDER <= OLDER); \ 596 EXPECT_FALSE(YOUNGER < YOUNGER); \ 597 EXPECT_FALSE(YOUNGER > YOUNGER); \ 598 EXPECT_TRUE(YOUNGER >= YOUNGER); \ 599 EXPECT_TRUE(YOUNGER <= YOUNGER); \ 600 EXPECT_EQ(OLDER, OLDER); \ 601 EXPECT_NE(OLDER, YOUNGER); \ 602 EXPECT_LT(OLDER, YOUNGER); \ 603 EXPECT_LE(OLDER, YOUNGER); \ 604 EXPECT_GT(YOUNGER, OLDER); \ 605 EXPECT_GE(YOUNGER, OLDER); \ 627 #undef TEST_RELATIONAL 632 EXPECT_EQ(
"2015-01-02T03:04:06",
Format(second += 1));
633 EXPECT_EQ(
"2015-01-02T03:04:07",
Format(second + 1));
634 EXPECT_EQ(
"2015-01-02T03:04:08",
Format(2 + second));
635 EXPECT_EQ(
"2015-01-02T03:04:05",
Format(second - 1));
636 EXPECT_EQ(
"2015-01-02T03:04:05",
Format(second -= 1));
637 EXPECT_EQ(
"2015-01-02T03:04:05",
Format(second++));
638 EXPECT_EQ(
"2015-01-02T03:04:07",
Format(++second));
639 EXPECT_EQ(
"2015-01-02T03:04:07",
Format(second--));
640 EXPECT_EQ(
"2015-01-02T03:04:05",
Format(--second));
643 EXPECT_EQ(
"2015-01-02T03:05",
Format(minute += 1));
644 EXPECT_EQ(
"2015-01-02T03:06",
Format(minute + 1));
645 EXPECT_EQ(
"2015-01-02T03:07",
Format(2 + minute));
646 EXPECT_EQ(
"2015-01-02T03:04",
Format(minute - 1));
647 EXPECT_EQ(
"2015-01-02T03:04",
Format(minute -= 1));
648 EXPECT_EQ(
"2015-01-02T03:04",
Format(minute++));
649 EXPECT_EQ(
"2015-01-02T03:06",
Format(++minute));
650 EXPECT_EQ(
"2015-01-02T03:06",
Format(minute--));
651 EXPECT_EQ(
"2015-01-02T03:04",
Format(--minute));
654 EXPECT_EQ(
"2015-01-02T04",
Format(hour += 1));
655 EXPECT_EQ(
"2015-01-02T05",
Format(hour + 1));
656 EXPECT_EQ(
"2015-01-02T06",
Format(2 + hour));
657 EXPECT_EQ(
"2015-01-02T03",
Format(hour - 1));
658 EXPECT_EQ(
"2015-01-02T03",
Format(hour -= 1));
659 EXPECT_EQ(
"2015-01-02T03",
Format(hour++));
660 EXPECT_EQ(
"2015-01-02T05",
Format(++hour));
661 EXPECT_EQ(
"2015-01-02T05",
Format(hour--));
662 EXPECT_EQ(
"2015-01-02T03",
Format(--hour));
665 EXPECT_EQ(
"2015-01-03",
Format(day += 1));
666 EXPECT_EQ(
"2015-01-04",
Format(day + 1));
667 EXPECT_EQ(
"2015-01-05",
Format(2 + day));
668 EXPECT_EQ(
"2015-01-02",
Format(day - 1));
669 EXPECT_EQ(
"2015-01-02",
Format(day -= 1));
670 EXPECT_EQ(
"2015-01-02",
Format(day++));
671 EXPECT_EQ(
"2015-01-04",
Format(++day));
672 EXPECT_EQ(
"2015-01-04",
Format(day--));
673 EXPECT_EQ(
"2015-01-02",
Format(--day));
676 EXPECT_EQ(
"2015-02",
Format(month += 1));
677 EXPECT_EQ(
"2015-03",
Format(month + 1));
678 EXPECT_EQ(
"2015-04",
Format(2 + month));
679 EXPECT_EQ(
"2015-01",
Format(month - 1));
680 EXPECT_EQ(
"2015-01",
Format(month -= 1));
681 EXPECT_EQ(
"2015-01",
Format(month++));
682 EXPECT_EQ(
"2015-03",
Format(++month));
683 EXPECT_EQ(
"2015-03",
Format(month--));
684 EXPECT_EQ(
"2015-01",
Format(--month));
687 EXPECT_EQ(
"2016",
Format(year += 1));
688 EXPECT_EQ(
"2017",
Format(year + 1));
689 EXPECT_EQ(
"2018",
Format(2 + year));
690 EXPECT_EQ(
"2015",
Format(year - 1));
691 EXPECT_EQ(
"2015",
Format(year -= 1));
692 EXPECT_EQ(
"2015",
Format(year++));
693 EXPECT_EQ(
"2017",
Format(++year));
694 EXPECT_EQ(
"2017",
Format(year--));
695 EXPECT_EQ(
"2015",
Format(--year));
698 TEST(CivilTime, ArithmeticLimits) {
699 const int kIntMax = std::numeric_limits<int>::max();
700 const int kIntMin = std::numeric_limits<int>::min();
704 EXPECT_EQ(
"2038-01-19T03:14:07",
Format(second));
706 EXPECT_EQ(
"1970-01-01T00:00:00",
Format(second));
708 EXPECT_EQ(
"1901-12-13T20:45:52",
Format(second));
710 EXPECT_EQ(
"1970-01-01T00:00:00",
Format(second));
714 EXPECT_EQ(
"6053-01-23T02:07",
Format(minute));
716 EXPECT_EQ(
"1970-01-01T00:00",
Format(minute));
718 EXPECT_EQ(
"-2114-12-08T21:52",
Format(minute));
720 EXPECT_EQ(
"1970-01-01T00:00",
Format(minute));
724 EXPECT_EQ(
"246953-10-09T07",
Format(hour));
726 EXPECT_EQ(
"1970-01-01T00",
Format(hour));
728 EXPECT_EQ(
"-243014-03-24T16",
Format(hour));
730 EXPECT_EQ(
"1970-01-01T00",
Format(hour));
734 EXPECT_EQ(
"5881580-07-11",
Format(day));
736 EXPECT_EQ(
"1970-01-01",
Format(day));
738 EXPECT_EQ(
"-5877641-06-23",
Format(day));
740 EXPECT_EQ(
"1970-01-01",
Format(day));
744 EXPECT_EQ(
"178958940-08",
Format(month));
746 EXPECT_EQ(
"1970-01",
Format(month));
748 EXPECT_EQ(
"-178955001-05",
Format(month));
750 EXPECT_EQ(
"1970-01",
Format(month));
754 EXPECT_EQ(
"2147483647",
Format(year));
756 EXPECT_EQ(
"0",
Format(year));
758 EXPECT_EQ(
"-2147483648",
Format(year));
760 EXPECT_EQ(
"0",
Format(year));
763 TEST(CivilTime, ArithmeticDifference) {
765 EXPECT_EQ(0, second - second);
766 EXPECT_EQ(10, (second + 10) - second);
767 EXPECT_EQ(-10, (second - 10) - second);
770 EXPECT_EQ(0, minute - minute);
771 EXPECT_EQ(10, (minute + 10) - minute);
772 EXPECT_EQ(-10, (minute - 10) - minute);
775 EXPECT_EQ(0, hour - hour);
776 EXPECT_EQ(10, (hour + 10) - hour);
777 EXPECT_EQ(-10, (hour - 10) - hour);
780 EXPECT_EQ(0, day - day);
781 EXPECT_EQ(10, (day + 10) - day);
782 EXPECT_EQ(-10, (day - 10) - day);
785 EXPECT_EQ(0, month - month);
786 EXPECT_EQ(10, (month + 10) - month);
787 EXPECT_EQ(-10, (month - 10) - month);
790 EXPECT_EQ(0, year - year);
791 EXPECT_EQ(10, (year + 10) - year);
792 EXPECT_EQ(-10, (year - 10) - year);
795 TEST(CivilTime, DifferenceLimits) {
796 const int kIntMax = std::numeric_limits<int>::max();
797 const int kIntMin = std::numeric_limits<int>::min();
800 const civil_day max_day(kIntMax, 12, 31);
801 EXPECT_EQ(1, max_day - (max_day - 1));
802 EXPECT_EQ(-1, (max_day - 1) - max_day);
806 EXPECT_EQ(1, (min_day + 1) - min_day);
807 EXPECT_EQ(-1, min_day - (min_day + 1));
812 EXPECT_EQ(kIntMax, d2 - d1);
813 EXPECT_EQ(kIntMin, d1 - (d2 + 1));
818 EXPECT_EQ(2015, ss.
year());
819 EXPECT_EQ(2, ss.
month());
820 EXPECT_EQ(3, ss.
day());
821 EXPECT_EQ(4, ss.
hour());
822 EXPECT_EQ(5, ss.
minute());
823 EXPECT_EQ(6, ss.
second());
826 EXPECT_EQ(2015, mm.year());
827 EXPECT_EQ(2, mm.month());
828 EXPECT_EQ(3, mm.day());
829 EXPECT_EQ(4, mm.hour());
830 EXPECT_EQ(5, mm.minute());
831 EXPECT_EQ(0, mm.second());
834 EXPECT_EQ(2015, hh.year());
835 EXPECT_EQ(2, hh.month());
836 EXPECT_EQ(3, hh.day());
837 EXPECT_EQ(4, hh.hour());
838 EXPECT_EQ(0, hh.minute());
839 EXPECT_EQ(0, hh.second());
842 EXPECT_EQ(2015, d.year());
843 EXPECT_EQ(2, d.month());
844 EXPECT_EQ(3, d.day());
845 EXPECT_EQ(0, d.hour());
846 EXPECT_EQ(0, d.minute());
847 EXPECT_EQ(0, d.second());
852 EXPECT_EQ(2015, m.
year());
853 EXPECT_EQ(2, m.
month());
854 EXPECT_EQ(1, m.
day());
855 EXPECT_EQ(0, m.
hour());
860 EXPECT_EQ(2015, y.year());
861 EXPECT_EQ(1, y.month());
862 EXPECT_EQ(1, y.day());
863 EXPECT_EQ(0, y.hour());
864 EXPECT_EQ(0, y.minute());
865 EXPECT_EQ(0, y.second());
868 TEST(CivilTime, OutputStream) {
883 EXPECT_EQ(
"Monday",
Format(weekday::monday));
884 EXPECT_EQ(
"Tuesday",
Format(weekday::tuesday));
885 EXPECT_EQ(
"Wednesday",
Format(weekday::wednesday));
886 EXPECT_EQ(
"Thursday",
Format(weekday::thursday));
887 EXPECT_EQ(
"Friday",
Format(weekday::friday));
888 EXPECT_EQ(
"Saturday",
Format(weekday::saturday));
889 EXPECT_EQ(
"Sunday",
Format(weekday::sunday));
892 TEST(CivilTime, OutputStreamLeftFillWidth) {
895 std::stringstream ss;
896 ss << std::left << std::setfill(
'.');
897 ss << std::setw(3) <<
'X';
899 ss << std::setw(3) <<
'X';
900 EXPECT_EQ(
"X..2016.................X..", ss.str());
903 std::stringstream ss;
904 ss << std::left << std::setfill(
'.');
905 ss << std::setw(3) <<
'X';
907 ss << std::setw(3) <<
'X';
908 EXPECT_EQ(
"X..2016-02..............X..", ss.str());
911 std::stringstream ss;
912 ss << std::left << std::setfill(
'.');
913 ss << std::setw(3) <<
'X';
915 ss << std::setw(3) <<
'X';
916 EXPECT_EQ(
"X..2016-02-03...........X..", ss.str());
919 std::stringstream ss;
920 ss << std::left << std::setfill(
'.');
921 ss << std::setw(3) <<
'X';
923 ss << std::setw(3) <<
'X';
924 EXPECT_EQ(
"X..2016-02-03T04........X..", ss.str());
927 std::stringstream ss;
928 ss << std::left << std::setfill(
'.');
929 ss << std::setw(3) <<
'X';
931 ss << std::setw(3) <<
'X';
932 EXPECT_EQ(
"X..2016-02-03T04:05.....X..", ss.str());
935 std::stringstream ss;
936 ss << std::left << std::setfill(
'.');
937 ss << std::setw(3) <<
'X';
939 ss << std::setw(3) <<
'X';
940 EXPECT_EQ(
"X..2016-02-03T04:05:06..X..", ss.str());
944 TEST(CivilTime, NextPrevWeekday) {
947 EXPECT_EQ(weekday::thursday,
get_weekday(thursday));
951 EXPECT_EQ(7, d - thursday) <<
Format(d);
952 EXPECT_EQ(d - 14,
prev_weekday(thursday, weekday::thursday));
956 EXPECT_EQ(1, d - thursday) <<
Format(d);
957 EXPECT_EQ(d - 7,
prev_weekday(thursday, weekday::friday));
961 EXPECT_EQ(2, d - thursday) <<
Format(d);
962 EXPECT_EQ(d - 7,
prev_weekday(thursday, weekday::saturday));
966 EXPECT_EQ(3, d - thursday) <<
Format(d);
967 EXPECT_EQ(d - 7,
prev_weekday(thursday, weekday::sunday));
971 EXPECT_EQ(4, d - thursday) <<
Format(d);
972 EXPECT_EQ(d - 7,
prev_weekday(thursday, weekday::monday));
976 EXPECT_EQ(5, d - thursday) <<
Format(d);
977 EXPECT_EQ(d - 7,
prev_weekday(thursday, weekday::tuesday));
981 EXPECT_EQ(6, d - thursday) <<
Format(d);
982 EXPECT_EQ(d - 7,
prev_weekday(thursday, weekday::wednesday));
985 TEST(CivilTime, NormalizeWithHugeYear) {
987 EXPECT_EQ(
"9223372036854775807-01",
Format(c));
989 EXPECT_EQ(
"9223372036854775806-12",
Format(c));
992 EXPECT_EQ(
"-9223372036854775808-01",
Format(c));
994 EXPECT_EQ(
"-9223372036854775807-01",
Format(c));
1007 {1900, 365, {3, 1}},
1008 {1999, 365, {3, 1}},
1009 {2000, 366, {2, 29}},
1010 {2001, 365, {3, 1}},
1011 {2002, 365, {3, 1}},
1012 {2003, 365, {3, 1}},
1013 {2004, 366, {2, 29}},
1014 {2005, 365, {3, 1}},
1015 {2006, 365, {3, 1}},
1016 {2007, 365, {3, 1}},
1017 {2008, 366, {2, 29}},
1018 {2009, 365, {3, 1}},
1019 {2100, 365, {3, 1}},
1022 for (
const auto& e : kLeapYearTable) {
1026 EXPECT_EQ(e.leap_day.month, next_day.
month());
1027 EXPECT_EQ(e.leap_day.day, next_day.
day());
1036 TEST(CivilTime, FirstThursdayInMonth) {
1039 EXPECT_EQ(
"2014-11-06",
Format(thursday));
1043 const civil_day thanksgiving = thursday + 7 * 3;
1044 EXPECT_EQ(
"2014-11-27",
Format(thanksgiving));
CONSTEXPR_F int get_yearday(const civil_day &cd) noexcept
detail::civil_year civil_year
#define TEST_RELATIONAL(OLDER, YOUNGER)
CONSTEXPR_M int minute() const noexcept
CONSTEXPR_M int day() const noexcept
CONSTEXPR_F civil_day next_weekday(civil_day cd, weekday wd) noexcept
CONSTEXPR_F weekday get_weekday(const civil_day &cd) noexcept
detail::civil_day civil_day
detail::civil_month civil_month
detail::civil_hour civil_hour
CONSTEXPR_M year_t year() const noexcept
AllocList * next[kMaxLevel]
CONSTEXPR_M int month() const noexcept
CONSTEXPR_F civil_day prev_weekday(civil_day cd, weekday wd) noexcept
CONSTEXPR_M int second() const noexcept
bool Format(FormatRawSink raw_sink, const FormatSpec< Args... > &format, const Args &...args)
detail::civil_minute civil_minute
CONSTEXPR_M int hour() const noexcept
TEST(CivilTime, DefaultConstruction)
detail::civil_second civil_second