2018-01-01 15:47:41 +11:00
|
|
|
#include "tap.hpp"
|
|
|
|
|
|
|
|
#include "time/parse.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int, char**)
|
|
|
|
{
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::TAP::logger tap;
|
2018-01-01 15:47:41 +11:00
|
|
|
|
|
|
|
static const char* BAD[] = {
|
|
|
|
"",
|
|
|
|
"foo"
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const auto &t: BAD) {
|
|
|
|
tap.expect_throw<std::invalid_argument> (
|
2018-08-05 14:42:02 +10:00
|
|
|
[t] () { cruft::time::iso8601::parse (t); },
|
2018-01-01 15:47:41 +11:00
|
|
|
"invalid timestamp '%s'", t
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
using namespace std::chrono_literals;
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
const char *string;
|
|
|
|
std::chrono::nanoseconds value;
|
|
|
|
const char *message;
|
|
|
|
} DECODE[] = {
|
|
|
|
{ "1970-01-01T00:00:00Z", 0s, "UNIX epoch" },
|
|
|
|
{ "1970-01-01T01:01:00+01:01", 0s, "UNIX epoch, +offset" },
|
|
|
|
{ "1985-04-12T23:20:50.52Z", 482196050520ms, "fractional UTC time" },
|
|
|
|
{ "2000-02-28T01:00:00Z", 951699600s, "leap year, pre-29th" },
|
|
|
|
{ "2000-02-29T01:00:00Z", 951786000s, "leap year, on-29th" },
|
|
|
|
{ "2000-03-01T01:00:00Z", 951872400s, "leap year, post-29th" },
|
|
|
|
{ "1990-12-31T23:59:60Z", 662688000s, "1990 leap second in UTC" },
|
|
|
|
{ "1990-12-31T15:59:60-08:00", 662688000s, "1990 leap second in PST" },
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const auto &t: DECODE) {
|
2018-08-05 14:42:02 +10:00
|
|
|
auto val = cruft::time::iso8601::parse (t.string);
|
2018-01-01 15:47:41 +11:00
|
|
|
tap.expect_eq (val, t.value, "%s", t.message);
|
|
|
|
}
|
|
|
|
|
|
|
|
tap.expect_eq (
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::time::iso8601::parse ("1996-12-19T16:39:57-08:00"),
|
|
|
|
cruft::time::iso8601::parse ("1996-12-20T00:39:57Z"),
|
2018-01-01 15:47:41 +11:00
|
|
|
"timezone equivalence"
|
|
|
|
);
|
|
|
|
|
|
|
|
return tap.status ();
|
|
|
|
}
|