8 #include "xclox/datetime.hpp"
10 using namespace xclox;
11 using namespace std::chrono;
13 TEST_SUITE(
"DateTime")
15 constexpr seconds NtpDeltaSeconds { 2208988800 };
16 constexpr seconds UnixRolloverSeconds { 2147483647 };
18 auto compare = [](
const DateTime& dt,
int year,
int month,
int day,
int hour,
int minute,
int second,
int milli,
int micro,
int nano) {
19 return dt.
year() == year && dt.
month() == month && dt.
day() == day
24 TEST_CASE(
"constructible")
30 CHECK(compare(dt, 0, 0, 0, 0, 0, 0, 0, 0, 0));
34 SUBCASE(
"before unix rollover")
37 DateTime dt2(UnixRolloverSeconds - seconds(1) + nanoseconds(999999999));
38 DateTime dt3(system_clock::time_point(UnixRolloverSeconds - seconds(1) + microseconds(999999)));
40 CHECK(compare(dt1, 2038, 1, 19, 3, 14, 6, 999, 999999, 999999999));
41 CHECK(compare(dt2, 2038, 1, 19, 3, 14, 6, 999, 999999, 999999999));
42 CHECK(compare(dt3, 2038, 1, 19, 3, 14, 6, 999, 999999, 999999000));
44 SUBCASE(
"unix rollover")
48 DateTime dt3(system_clock::time_point { UnixRolloverSeconds });
50 CHECK(compare(dt1, 2038, 1, 19, 3, 14, 7, 0, 0, 0));
51 CHECK(compare(dt2, 2038, 1, 19, 3, 14, 7, 0, 0, 0));
52 CHECK(compare(dt3, 2038, 1, 19, 3, 14, 7, 0, 0, 0));
54 SUBCASE(
"after unix rollover")
57 DateTime dt2(UnixRolloverSeconds + milliseconds(1500));
58 DateTime dt3(system_clock::time_point(UnixRolloverSeconds + milliseconds(1500)));
60 CHECK(compare(dt1, 2038, 1, 19, 3, 14, 8, 500, 500000, 500000000));
61 CHECK(compare(dt2, 2038, 1, 19, 3, 14, 8, 500, 500000, 500000000));
62 CHECK(compare(dt3, 2038, 1, 19, 3, 14, 8, 500, 500000, 500000000));
64 SUBCASE(
"before unix epoch")
67 DateTime dt2(nanoseconds(-876543211));
68 DateTime dt3(system_clock::time_point(microseconds(-876544)));
70 CHECK(compare(dt1, 1969, 12, 31, 23, 59, 59, 123, 123456, 123456789));
71 CHECK(compare(dt2, 1969, 12, 31, 23, 59, 59, 123, 123456, 123456789));
72 CHECK(compare(dt3, 1969, 12, 31, 23, 59, 59, 123, 123456, 123456000));
78 DateTime dt3(system_clock::time_point(seconds(0)));
80 CHECK(compare(dt1, 1970, 1, 1, 0, 0, 0, 0, 0, 0));
81 CHECK(compare(dt2, 1970, 1, 1, 0, 0, 0, 0, 0, 0));
82 CHECK(compare(dt3, 1970, 1, 1, 0, 0, 0, 0, 0, 0));
84 SUBCASE(
"after unix epoch")
88 DateTime dt3(system_clock::time_point(microseconds(1)));
90 CHECK(compare(dt1, 1970, 1, 1, 0, 0, 0, 0, 0, 1));
91 CHECK(compare(dt2, 1970, 1, 1, 0, 0, 0, 0, 0, 1));
92 CHECK(compare(dt3, 1970, 1, 1, 0, 0, 0, 0, 1, 1000));
94 SUBCASE(
"before ntp epoch")
97 DateTime dt2(-NtpDeltaSeconds - nanoseconds(1));
98 DateTime dt3(system_clock::time_point(-NtpDeltaSeconds - microseconds(1)));
100 CHECK(compare(dt1, 1899, 12, 31, 23, 59, 59, 999, 999999, 999999999));
101 CHECK(compare(dt2, 1899, 12, 31, 23, 59, 59, 999, 999999, 999999999));
102 CHECK(compare(dt3, 1899, 12, 31, 23, 59, 59, 999, 999999, 999999000));
108 DateTime dt3(system_clock::time_point(-NtpDeltaSeconds));
110 CHECK(compare(dt1, 1900, 1, 1, 0, 0, 0, 0, 0, 0));
111 CHECK(compare(dt2, 1900, 1, 1, 0, 0, 0, 0, 0, 0));
112 CHECK(compare(dt3, 1900, 1, 1, 0, 0, 0, 0, 0, 0));
114 SUBCASE(
"after ntp epoch")
117 DateTime dt2(-NtpDeltaSeconds + nanoseconds(1));
118 DateTime dt3(system_clock::time_point(-NtpDeltaSeconds + microseconds(1)));
120 CHECK(compare(dt1, 1900, 1, 1, 0, 0, 0, 0, 0, 1));
121 CHECK(compare(dt2, 1900, 1, 1, 0, 0, 0, 0, 0, 1));
122 CHECK(compare(dt3, 1900, 1, 1, 0, 0, 0, 0, 1, 1000));
127 TEST_CASE(
"validatable")
129 CHECK(
DateTime().isValid() ==
false);
134 CHECK(
DateTime(microseconds(-1)).isValid() ==
true);
135 CHECK(
DateTime(system_clock::time_point(microseconds(-1))).isValid() ==
true);
139 CHECK(
DateTime(system_clock::now().time_since_epoch()).isValid() ==
true);
140 CHECK(
DateTime(system_clock::now()).isValid() ==
true);
145 TEST_CASE(
"comparable")
147 CHECK(
DateTime(
Date(2012, 3, 27),
Time(8, 55, 21,
Time::Nanoseconds(123456789))) <
DateTime(
Date(2017, 3, 27),
Time(8, 55, 21,
Time::Nanoseconds(123456789))));
148 CHECK(
DateTime(
Date(2012, 3, 27),
Time(8, 55, 21,
Time::Nanoseconds(123456789))) <=
DateTime(
Date(2017, 3, 27),
Time(8, 55, 21,
Time::Nanoseconds(123456789))));
149 CHECK(
DateTime(
Date(2012, 3, 27),
Time(8, 55, 21,
Time::Nanoseconds(123456789))) <=
DateTime(
Date(2012, 3, 27),
Time(8, 55, 21,
Time::Nanoseconds(123456789))));
150 CHECK(
DateTime(
Date(2012, 9, 27),
Time(8, 55, 21,
Time::Nanoseconds(123456789))) >
DateTime(
Date(2012, 3, 27),
Time(8, 55, 21,
Time::Nanoseconds(123456789))));
151 CHECK(
DateTime(
Date(2012, 3, 27),
Time(9, 55, 21,
Time::Nanoseconds(123456789))) >=
DateTime(
Date(2012, 3, 27),
Time(8, 55, 21,
Time::Nanoseconds(123456789))));
152 CHECK(
DateTime(
Date(2015, 3, 27),
Time(1, 55, 21,
Time::Nanoseconds(123456789))) >=
DateTime(
Date(2015, 3, 27),
Time(1, 55, 21,
Time::Nanoseconds(123456789))));
153 CHECK(
DateTime(
Date(2012, 3, 27),
Time(8, 55, 21,
Time::Nanoseconds(123456789))) ==
DateTime(
Date(2012, 3, 27),
Time(8, 55, 21,
Time::Nanoseconds(123456789))));
154 CHECK(
DateTime(
Date(2017, 12, 6),
Time(16, 32, 4,
Time::Nanoseconds(987654321))) !=
DateTime(
Date(2012, 3, 27),
Time(8, 55, 21,
Time::Nanoseconds(123456789))));
157 TEST_CASE(
"copyable")
163 SUBCASE(
"construction")
173 SUBCASE(
"assignment")
185 TEST_CASE(
"current datetime")
187 CHECK(abs(duration_cast<milliseconds>(
DateTime::current().toStdTimePoint() - system_clock::now()).count()) < 100);
195 TEST_CASE(
"addition & subtraction")
197 SUBCASE(
"add duration")
200 CHECK(
DateTime(
Date(2045, 3, 27),
Time(16, 2, 3, 4)).addDuration(
DateTime::Minutes(10)) ==
DateTime(
Date(2045, 3, 27),
Time(16, 12, 3, 4)));
201 CHECK(
DateTime(
Date(2045, 3, 27),
Time(1, 2, 3, 4)).addDuration(
DateTime::Hours(3)) ==
DateTime(
Date(2045, 3, 27),
Time(4, 2, 3, 4)));
203 CHECK(
DateTime(
Date(2045, 3, 27),
Time(16, 2, 3, 4)).addDuration(
DateTime::Hours(10)) ==
DateTime(
Date(2045, 3, 28),
Time(2, 2, 3, 4)));
205 CHECK(
DateTime(
Date(2045, 3, 27),
Time(1, 2, 3, 4)).addDuration(
DateTime::Days(3)) ==
DateTime(
Date(2045, 3, 30),
Time(1, 2, 3, 4)));
207 CHECK(
DateTime(
Date(2045, 3, 27),
Time(1, 2, 3, 4)).addDuration(-
DateTime::Days(3)) ==
DateTime(
Date(2045, 3, 24),
Time(1, 2, 3, 4)));
209 SUBCASE(
"subtract duration")
212 CHECK(
DateTime(
Date(2045, 3, 27),
Time(16, 2, 3, 4)).subtractDuration(
DateTime::Minutes(10)) ==
DateTime(
Date(2045, 3, 27),
Time(15, 52, 3, 4)));
213 CHECK(
DateTime(
Date(2045, 3, 27),
Time(7, 2, 3, 4)).subtractDuration(
DateTime::Hours(3)) ==
DateTime(
Date(2045, 3, 27),
Time(4, 2, 3, 4)));
215 CHECK(
DateTime(
Date(2045, 3, 27),
Time(6, 2, 3, 4)).subtractDuration(
DateTime::Hours(10)) ==
DateTime(
Date(2045, 3, 26),
Time(20, 2, 3, 4)));
217 CHECK(
DateTime(
Date(2045, 3, 27),
Time(1, 2, 3, 4)).subtractDuration(
DateTime::Days(3)) ==
DateTime(
Date(2045, 3, 24),
Time(1, 2, 3, 4)));
219 CHECK(
DateTime(
Date(2045, 3, 27),
Time(1, 2, 3, 4)).subtractDuration(-
DateTime::Days(3)) ==
DateTime(
Date(2045, 3, 30),
Time(1, 2, 3, 4)));
223 CHECK((
DateTime(
Date(2017, 3, 27),
Time(22, 19, 53, 4)) -
DateTime(
Date(2017, 3, 26),
Time(22, 12, 53, 4))) ==
DateTime::Days(1) +
DateTime::Minutes(7));
224 CHECK((
DateTime(
Date(2017, 12, 29),
Time(23, 12, 53, 4)) +
DateTime::Hours(35)) ==
DateTime(
Date(2017, 12, 31),
Time(10, 12, 53, 4)));
225 CHECK((
DateTime(
Date(2017, 12, 31),
Time(10, 12, 53, 4)) -
DateTime::Hours(35)) ==
DateTime(
Date(2017, 12, 29),
Time(23, 12, 53, 4)));
229 TEST_CASE(
"formatting")
231 SUBCASE(
"empty format")
235 SUBCASE(
"era of year")
237 SUBCASE(
"positive(+) or negative(-) sign")
250 SUBCASE(
"minimum number of digits (1, 9999)")
255 SUBCASE(
"two digits (00, 99)")
262 SUBCASE(
"four digits (0000, 9999)")
265 CHECK(
DateTime(
Date(12345, 2, 3),
Time(4, 5, 6)).toString(
"yyyy") ==
"2345");
270 SUBCASE(
"minimum number of digits (1, 12)")
274 SUBCASE(
"two digits (01, 12)")
278 SUBCASE(
"short name (e.g. Feb)")
282 SUBCASE(
"long name (e.g. February)")
284 CHECK(
DateTime(
Date(1, 1, 3),
Time(4, 5, 6)).toString(
"MMMM") ==
"January");
289 SUBCASE(
"day of month as one digit or more (1, 31)")
293 SUBCASE(
"day of month as two digits (00, 31)")
297 SUBCASE(
"day of week as short name (e.g. Fri)")
301 SUBCASE(
"day of week as long name (e.g. Friday)")
303 CHECK(
DateTime(
Date(2024, 2, 18),
Time(4, 5, 6)).toString(
"dddd") ==
"Sunday");
308 SUBCASE(
"24-hour clock")
310 SUBCASE(
"minimum number of digits (0, 23)")
314 SUBCASE(
"two digits (00, 23)")
319 SUBCASE(
"12-hour clock")
321 SUBCASE(
"minimum number of digits (0, 23)")
327 SUBCASE(
"two digits (00, 23)")
332 SUBCASE(
"before/after noon indicator")
343 CHECK(dt2.toString(
"a") ==
"am");
344 CHECK(dt3.toString(
"a") ==
"pm");
345 CHECK(dt4.toString(
"a") ==
"pm");
350 CHECK(dt2.toString(
"A") ==
"AM");
351 CHECK(dt3.toString(
"A") ==
"PM");
352 CHECK(dt4.toString(
"A") ==
"PM");
358 SUBCASE(
"minimum number of digits (0, 59)")
362 SUBCASE(
"two digits (00, 59)")
369 SUBCASE(
"minimum number of digits (0, 59)")
373 SUBCASE(
"two digits (00, 59)")
383 SUBCASE(
"one-digit subsecond (0, 9)")
386 CHECK(dt2.toString(
"f") ==
"1");
388 SUBCASE(
"nine-digit subsecond (000000000, 999999999)")
390 CHECK(dt1.
toString(
"fffffffff") ==
"000000000");
391 CHECK(dt2.toString(
"fffffffff") ==
"123456780");
394 SUBCASE(
"unrecognized flags are preserved")
396 const auto& text =
"- GNU'S NOT UNIX!";
399 SUBCASE(
"combinations of format specifiers")
402 CHECK_EQ(dt.
toString(
" # E y-yy-yyyy M-MM-MMM-MMMM d-dd-ddd-dddd h-hh-m-mm-s-ss f-ff-fff-ffff-fffff-ffffff-fffffff-ffffffff-fffffffff a A "),
403 " + CE 2024-24-2024 2-02-Feb-February 18-18-Sun-Sunday 21-21-46-46-7-07 9-98-987-9876-98765-987654-9876543-98765432-987654321 pm PM ");
405 SUBCASE(
"flags with unrecognized length are preserved")
408 CHECK(dt.
toString(
" yyy yyyyy ddddd MMMMM hhh mmm sss ffffffffff ") ==
" yyy yyyyy ddddd MMMMM hhh mmm sss ffffffffff ");
410 SUBCASE(
"default format")
414 SUBCASE(
"invalid date or time")
416 CHECK(
DateTime().toString(
"d/M/yyyy, hh:mm:ss.fffffffff") ==
"");
417 CHECK(
DateTime(
Date(0, 0, 0),
Time(-4, -5, 66)).toString(
"#y-M-d h:m:s.f") ==
"");
418 CHECK(
DateTime(
Date(1, -2, -3),
Time(4, 5, 6)).toString(
"E yy-MMM-ddd h-mm-ss A") ==
"");
419 CHECK(
DateTime(
Date(0, 2, 3),
Time(4, 5, 6, -9)).toString(
"@ yyyy-MM-dd hh:mm:ss.fff a") ==
"");
429 const auto& format =
"yyyy-MM-dd hh:mm:ss.fffffffff";
431 CHECK(
DateTime(-NtpDeltaSeconds - seconds(1)).toString(format) ==
"1899-12-31 23:59:59.000000000");
432 CHECK(
DateTime(-NtpDeltaSeconds - nanoseconds(1)).toString(format) ==
"1899-12-31 23:59:59.999999999");
433 CHECK(
DateTime(-NtpDeltaSeconds).toString(format) ==
"1900-01-01 00:00:00.000000000");
434 CHECK(
DateTime(-NtpDeltaSeconds + nanoseconds(1)).toString(format) ==
"1900-01-01 00:00:00.000000001");
435 CHECK(
DateTime(-NtpDeltaSeconds + seconds(1)).toString(format) ==
"1900-01-01 00:00:01.000000000");
437 CHECK(
DateTime(-seconds(1)).toString(format) ==
"1969-12-31 23:59:59.000000000");
438 CHECK(
DateTime(-nanoseconds(1)).toString(format) ==
"1969-12-31 23:59:59.999999999");
439 CHECK(
DateTime(seconds(0)).toString(format) ==
"1970-01-01 00:00:00.000000000");
440 CHECK(
DateTime(nanoseconds(1)).toString(format) ==
"1970-01-01 00:00:00.000000001");
441 CHECK(
DateTime(seconds(1)).toString(format) ==
"1970-01-01 00:00:01.000000000");
443 CHECK(
DateTime(UnixRolloverSeconds - seconds(1)).toString(format) ==
"2038-01-19 03:14:06.000000000");
444 CHECK(
DateTime(UnixRolloverSeconds - nanoseconds(1)).toString(format) ==
"2038-01-19 03:14:06.999999999");
445 CHECK(
DateTime(UnixRolloverSeconds).toString(format) ==
"2038-01-19 03:14:07.000000000");
446 CHECK(
DateTime(UnixRolloverSeconds + nanoseconds(1)).toString(format) ==
"2038-01-19 03:14:07.000000001");
447 CHECK(
DateTime(UnixRolloverSeconds + seconds(1)).toString(format) ==
"2038-01-19 03:14:08.000000000");
454 SUBCASE(
"minimum number of digits (1, 9999)")
456 SUBCASE(
"single digit")
460 SUBCASE(
"multiple digits")
464 SUBCASE(
"limited to four digits")
469 SUBCASE(
"year of era as two digits (00, 99)")
473 SUBCASE(
"year as four digits (0000, 9999)")
478 SUBCASE(
"era of year")
480 SUBCASE(
"positive(+) or negative(-) sign")
484 SUBCASE(
"located after the year")
493 SUBCASE(
"located before the year")
500 SUBCASE(
"unrecognized characters are skipped according to the format")
506 SUBCASE(
"minimum number of digits (1, 12)")
509 SUBCASE(
"greedy when there is one more digit")
514 SUBCASE(
"two digits (01, 12)")
518 SUBCASE(
"short name (e.g. Feb)")
520 CHECK(internal::getShortMonthNumber(
"abc") == 13);
522 SUBCASE(
"case insensitive")
526 SUBCASE(
"the second pattern takes effect in case of multiple occurences")
531 SUBCASE(
"long name (e.g. February)")
533 CHECK(internal::getLongMonthNumber(
"abcdef") == 13);
535 SUBCASE(
"case insensitive")
539 SUBCASE(
"followed by an interfering expression")
547 SUBCASE(
"day of month")
551 SUBCASE(
"day of week as short name (e.g. Fri)")
553 CHECK(internal::search(internal::getShortWeekdayNameArray(),
"mon") == 0);
554 CHECK(internal::search(internal::getShortWeekdayNameArray(),
"abc") == 7);
557 SUBCASE(
"day of week as long name (e.g. Friday)")
559 CHECK(internal::search(internal::getLongWeekdayNameArray(),
"MONDAY") == 0);
560 CHECK(internal::search(internal::getLongWeekdayNameArray(),
"a") == 7);
566 SUBCASE(
"24-hour clock")
570 SUBCASE(
"12-hour clock")
588 SUBCASE(
"single digit (0, 9)")
592 SUBCASE(
"multiple digits (000000000, 999999999)")
597 SUBCASE(
"flags with unrecognized length are ignored")
601 CHECK(
DateTime::fromString(
"1999-08-07 01:02:03",
"yyyy-MMMMMM-dd hh:mm:ss").isValid() ==
false);
602 CHECK(
DateTime::fromString(
"1999-08-07 01:02:03",
"yyyy-MM-ddddd hh:mm:ss").isValid() ==
false);
606 CHECK(
DateTime::fromString(
"1999-08-07 01:02:03.123456789",
"yyyy-MM-dd hh:mm:ss.ffffffffff").isValid() ==
false);
607 CHECK(
DateTime::fromString(
"1999-08-07 01:02:03.0 CE",
"yyyy-MM-dd hh:mm:ss.f EE").isValid() ==
false);
608 CHECK(
DateTime::fromString(
"1999-08-07 01:02:03.0 am",
"yyyy-MM-dd hh:mm:ss.f aa").isValid() ==
false);
609 CHECK(
DateTime::fromString(
"1999-08-07 01:02:03.0 AM",
"yyyy-MM-dd hh:mm:ss.f AA").isValid() ==
false);
611 SUBCASE(
"missing data yields invalid objects")
630 SUBCASE(
"unrecognized identical characters are skipped, so whitespaces may be used as placeholders")
634 SUBCASE(
"default format")
638 SUBCASE(
"empty format")
644 TEST_CASE(
"Julian day conversion")
648 CHECK(
DateTime(
Date(-4714, 11, 24),
Time(12, 0, 0)).toJulianDay() == doctest::Approx(0).epsilon(0.0000000001));
649 CHECK(
DateTime(
Date(-4714, 11, 26),
Time(0, 0, 0)).toJulianDay() == doctest::Approx(1.5).epsilon(0.0000000001));
650 CHECK(
DateTime(
Date(2017, 12, 31),
Time(00, 9, 35)).toJulianDay() == doctest::Approx(2458118.506655093).epsilon(0.0000000001));
662 CHECK(
DateTime::nanosecondsBetween(
DateTime(
Date(2017, 1, 15),
Time(12, 45, 36,
DateTime::Nanoseconds(123001013))),
DateTime(
Date(2017, 1, 15),
Time(12, 45, 37))) == 876998987);
663 CHECK(
DateTime::microsecondsBetween(
DateTime(
Date(2017, 1, 15),
Time(12, 45, 36,
DateTime::Microseconds(123001))),
DateTime(
Date(2017, 1, 15),
Time(12, 45, 37))) == 876999);
664 CHECK(
DateTime::millisecondsBetween(
DateTime(
Date(2017, 1, 15),
Time(12, 45, 36, 123)),
DateTime(
Date(2017, 1, 15),
Time(12, 45, 37))) == 877);
665 CHECK(
DateTime::secondsBetween(
DateTime(
Date(2002, 1, 1),
Time(15, 45, 36)),
DateTime(
Date(2002, 1, 2),
Time(15, 2, 37))) == 83821);
666 CHECK(
DateTime::minutesBetween(
DateTime(
Date(2000, 1, 2),
Time(23, 45, 36)),
DateTime(
Date(2000, 1, 2),
Time(12, 2, 36))) == 703);
667 CHECK(
DateTime::hoursBetween(
DateTime(
Date(1998, 1, 1),
Time(23, 45, 36)),
DateTime(
Date(1998, 1, 2),
Time(12, 2, 36))) == 12);
668 CHECK(
DateTime::daysBetween(
DateTime(
Date(1970, 1, 1),
Time(23, 2, 36)),
DateTime(
Date(1971, 1, 1),
Time(23, 2, 36))) == 365);
671 TEST_CASE(
"serialization & deserialization")
674 std::stringstream ss;
DateTime is an immutable class representing a datetime without a time zone in the ISO-8601 calendar s...
Definition: datetime.hpp:47
static long long secondsBetween(const DateTime &from, const DateTime &to)
Returns the number of seconds between from and to.
Definition: datetime.hpp:775
static long hoursBetween(const DateTime &from, const DateTime &to)
Returns the number of hours between from and to.
Definition: datetime.hpp:787
int year() const
Returns the year as a number. There is no year 0. Negative numbers indicate years before 1 CE; that i...
Definition: datetime.hpp:280
long microsecond() const
Returns the microsecond of second (0, 999999).
Definition: datetime.hpp:238
static DateTime fromJulianDay(double julianDay)
Returns a DateTime object corresponding to the Julian day julianDay. See toJulianDay() for informatio...
Definition: datetime.hpp:742
long nanosecond() const
Returns the nanosecond of second (0, 999999999).
Definition: datetime.hpp:232
int day() const
Returns the day of month (1, 31).
Definition: datetime.hpp:268
std::string toString(const std::string &format="yyyy-MM-dd hh:mm:ss") const
Returns the datetime as a string formatted according to the format string format.
Definition: datetime.hpp:655
static DateTime epoch()
Returns a DateTime object set to the epoch "1970-1-1T00:00:00".
Definition: datetime.hpp:680
static DateTime fromString(const std::string &datetime, const std::string &format="yyyy-MM-dd hh:mm:ss")
Returns a DateTime object from the string datetime formatted according to the format string format.
Definition: datetime.hpp:689
static long long millisecondsBetween(const DateTime &from, const DateTime &to)
Returns the number of milliseconds between from and to.
Definition: datetime.hpp:769
int minute() const
Returns the minute of hour (0, 59).
Definition: datetime.hpp:256
Time::Nanoseconds Nanoseconds
Nanosecond duration.
Definition: datetime.hpp:56
Time::Hours Hours
Hour duration.
Definition: datetime.hpp:61
Time::Minutes Minutes
Minute duration.
Definition: datetime.hpp:60
static long long microsecondsBetween(const DateTime &from, const DateTime &to)
Returns the number of microseconds between from and to.
Definition: datetime.hpp:763
int millisecond() const
Returns the millisecond of second (0, 999).
Definition: datetime.hpp:244
static long minutesBetween(const DateTime &from, const DateTime &to)
Returns the number of minutes between from and to.
Definition: datetime.hpp:781
Date::Days Days
Day duration.
Definition: datetime.hpp:62
static DateTime current()
Returns a DateTime object set to the current datetime obtained from the system clock.
Definition: datetime.hpp:674
static long long nanosecondsBetween(const DateTime &from, const DateTime &to)
Returns the number of nanoseconds between from and to.
Definition: datetime.hpp:757
int second() const
Returns the second of minute (0, 59).
Definition: datetime.hpp:250
static long daysBetween(const DateTime &from, const DateTime &to)
Returns the number of days between from and to.
Definition: datetime.hpp:793
Time::Microseconds Microseconds
Microsecond duration.
Definition: datetime.hpp:57
int hour() const
Returns the hour of day (0, 23).
Definition: datetime.hpp:262
int month() const
Returns the month of year (1, 12), which corresponds to the enumeration Month.
Definition: datetime.hpp:274
Date is an immutable class representing a date without a time zone in the ISO-8601 calendar system,...
Definition: date.hpp:84
Time is an immutable time class representing a time without a time zone in the ISO-8601 calendar syst...
Definition: time.hpp:46
std::chrono::milliseconds Milliseconds
Millisecond duration.
Definition: time.hpp:58
std::chrono::nanoseconds Nanoseconds
Nanosecond duration.
Definition: time.hpp:56
std::chrono::hours Hours
Hour duration.
Definition: time.hpp:61