108 CPPUNIT_ASSERT_EQUAL(2012, test1.year());
109 CPPUNIT_ASSERT_EQUAL(2, test1.month());
110 CPPUNIT_ASSERT_EQUAL(29, test1.day());
111 CPPUNIT_ASSERT_EQUAL(15, test1.hour());
112 CPPUNIT_ASSERT_EQUAL(34, test1.minute());
113 CPPUNIT_ASSERT_EQUAL(20, test1.second());
114 CPPUNIT_ASSERT_EQUAL(33, test1.millisecond());
115 CPPUNIT_ASSERT_EQUAL(DayOfWeek::Wednesday, test1.dayOfWeek());
116 CPPUNIT_ASSERT_EQUAL((31 + 29), test1.dayOfYear());
117 CPPUNIT_ASSERT(test1.isLeapYear());
120 CPPUNIT_ASSERT_EQUAL(
"Wed 2012-02-29 15:34:20.033"s, test1.toString(DateTimeOutputFormat::DateTimeAndShortWeekday));
122 CPPUNIT_ASSERT_EQUAL(1, test2.year());
123 CPPUNIT_ASSERT_EQUAL(1, test2.month());
124 CPPUNIT_ASSERT_EQUAL(1, test2.day());
125 CPPUNIT_ASSERT_EQUAL(15, test2.hour());
126 CPPUNIT_ASSERT_EQUAL(34, test2.minute());
127 CPPUNIT_ASSERT_EQUAL(20, test2.second());
128 CPPUNIT_ASSERT_EQUAL(33, test2.millisecond());
131 const auto timeStamp =
static_cast<time_t
>(1453840331);
133 CPPUNIT_ASSERT_EQUAL(
"Tue 2016-01-26 20:32:11"s, fromTimeStampGmt.toString(DateTimeOutputFormat::DateTimeAndShortWeekday));
134 CPPUNIT_ASSERT(fabs((fromTimeStamp - fromTimeStampGmt).totalDays()) <= 1.0);
136 CPPUNIT_ASSERT_EQUAL(timeStamp, fromTimeStampGmt.toTimeStamp());
140 CPPUNIT_ASSERT_EQUAL(
"Tue 2016-01-26 20:32:11"s, fromChronoTimePointGmt.toString(DateTimeOutputFormat::DateTimeAndShortWeekday));
155 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"surplus parts ignored", test1,
DateTime::fromString(
"2012-02-29 15:34:20.033:12"));
156 CPPUNIT_ASSERT_EQUAL(
"2012-02-29 15:34:20.033"s, test1.toString(DateTimeOutputFormat::DateAndTime,
false));
159 CPPUNIT_ASSERT_EQUAL(
"2016-08-29T21:32:31.125+02:00"s, test3.first.toIsoString(test3.second));
163 CPPUNIT_ASSERT_EQUAL(2.5, test4.second.totalHours());
164 CPPUNIT_ASSERT_EQUAL(15, test4.first.second());
165 CPPUNIT_ASSERT_EQUAL(985, test4.first.millisecond());
166 CPPUNIT_ASSERT_EQUAL(77, test4.first.microsecond());
167 CPPUNIT_ASSERT_EQUAL(600, test4.first.nanosecond());
168 CPPUNIT_ASSERT_EQUAL(
"2017-08-23T19:40:15.9850776+02:30"s, test4.first.toIsoString(test4.second));
171 CPPUNIT_ASSERT_EQUAL(-2.5, test5.second.totalHours());
172 CPPUNIT_ASSERT_EQUAL(15, test5.first.second());
173 CPPUNIT_ASSERT_EQUAL(985, test5.first.millisecond());
174 CPPUNIT_ASSERT_EQUAL(77, test5.first.microsecond());
175 CPPUNIT_ASSERT_EQUAL(600, test5.first.nanosecond());
176 CPPUNIT_ASSERT_EQUAL(
"2017-08-23T19:40:15.9850776-02:30"s, test5.first.toIsoString(test5.second));
184 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"no seconds fraction (positive timezone offset, 1)",
DateTime::fromDateAndTime(1970, 1, 1, 1, 2, 3), test6.first);
185 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"no seconds fraction (positive timezone offset, 2)",
TimeSpan::fromHours(1.0), test6.second);
187 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"no seconds fraction (negative timezone offset, 1)",
DateTime::fromDateAndTime(2021, 5, 20, 23, 2, 45), test7.first);
188 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"no seconds fraction (negative timezone offset, 2)",
TimeSpan::fromHours(-4.0), test7.second);
190 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"no separators", test5.first - test5.second,
DateTime::fromIsoStringGmt(
"20170823T194015.985077682-0230"));
191 CPPUNIT_ASSERT_EQUAL_MESSAGE(
204 CPPUNIT_ASSERT_EQUAL(
"1234-05-06T07:08:09.0105005"s,
DateTime::fromDateAndTime(1234, 5, 6, 7, 8, 9, 10.5005).toString(DateTimeOutputFormat::Iso));
205 CPPUNIT_ASSERT_EQUAL(
"1234-05-06T07:08:09.0105005"s,
207 CPPUNIT_ASSERT_EQUAL(
"1234-05-06T07:08:09.010500"s,
209 CPPUNIT_ASSERT_EQUAL(
210 "1234-05-06T07:08:09.010"s,
DateTime::fromDateAndTime(1234, 5, 6, 7, 8, 9, 10).toString(DateTimeOutputFormat::IsoOmittingDefaultComponents));
211 CPPUNIT_ASSERT_EQUAL(
212 "1234-05-06T07:08:09"s,
DateTime::fromDateAndTime(1234, 5, 6, 7, 8, 9).toString(DateTimeOutputFormat::IsoOmittingDefaultComponents));
213 CPPUNIT_ASSERT_EQUAL(
214 "1234-05-06T07:08"s,
DateTime::fromDateAndTime(1234, 5, 6, 7, 8).toString(DateTimeOutputFormat::IsoOmittingDefaultComponents));
215 CPPUNIT_ASSERT_EQUAL(
"1234-05-06T07"s,
DateTime::fromDateAndTime(1234, 5, 6, 7).toString(DateTimeOutputFormat::IsoOmittingDefaultComponents));
216 CPPUNIT_ASSERT_EQUAL(
"1234-05-06"s,
DateTime::fromDateAndTime(1234, 5, 6).toString(DateTimeOutputFormat::IsoOmittingDefaultComponents));
217 CPPUNIT_ASSERT_EQUAL(
"1234-05"s,
DateTime::fromDateAndTime(1234, 5).toString(DateTimeOutputFormat::IsoOmittingDefaultComponents));
218 CPPUNIT_ASSERT_EQUAL(
"1234"s,
DateTime::fromDateAndTime(1234).toString(DateTimeOutputFormat::IsoOmittingDefaultComponents));
219 CPPUNIT_ASSERT_EQUAL(
"0001"s,
DateTime().toString(DateTimeOutputFormat::IsoOmittingDefaultComponents));
222#if defined(PLATFORM_UNIX)