From: Philipp Gesang Date: Fri, 26 Apr 2019 07:40:39 +0000 (+0200) Subject: fix formatting of timezone in iso timestamps X-Git-Tag: v2.12~4^2~4 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=310af20b08b9763186fb2e43234f73f9ac033d7e;p=libi2ncommon fix formatting of timezone in iso timestamps The `Z' indicates UTC and has no place in timestamps with an explicit offset. --- diff --git a/src/timefunc.cpp b/src/timefunc.cpp index 26fbb23..dd69369 100644 --- a/src/timefunc.cpp +++ b/src/timefunc.cpp @@ -806,17 +806,17 @@ namespace iso8601 { static const char *const formatter [ISO8601_SIZE] = { /* [iso8601::d ] = */ "%4Y-%m-%d", /* [iso8601::t ] = */ "%T", - /* [iso8601::tz ] = */ "%TZ%z", + /* [iso8601::tz ] = */ "%T%z", /* [iso8601::dt ] = */ "%4Y-%m-%dT%T", - /* [iso8601::dtz] = */ "%4Y-%m-%dT%TZ%z", + /* [iso8601::dtz] = */ "%4Y-%m-%dT%T%z", }; static const char *const scanner [ISO8601_SIZE] = { /* [iso8601::d ] = */ "%Y-%m-%d", /* [iso8601::t ] = */ "%T", - /* [iso8601::tz ] = */ "%TZ%z", + /* [iso8601::tz ] = */ "%T%z", /* [iso8601::dt ] = */ "%Y-%m-%dT%T", - /* [iso8601::dtz] = */ "%Y-%m-%dT%TZ%z", + /* [iso8601::dtz] = */ "%Y-%m-%dT%T%z", }; static inline const char * @@ -952,7 +952,7 @@ scan_iso8601 (const char *s, } /* * Contrary to what the man page indicates, strptime(3) is *not* - * the inverse operation of strftime(3)! The later correctly formats + * the inverse operation of strftime(3)! The latter correctly formats * negative year numbers with the %F modifier wheres the former trips * over the sign character. */ diff --git a/test/test_timefunc.cpp b/test/test_timefunc.cpp index ebc22ae..1ee6e47 100644 --- a/test/test_timefunc.cpp +++ b/test/test_timefunc.cpp @@ -511,14 +511,14 @@ BOOST_AUTO_TEST_CASE(FormatISO8601_TZ_local) { this->set_tz ("CET"); const time_t moment = 1515492684; - BOOST_CHECK_EQUAL("11:11:24Z+0100", + BOOST_CHECK_EQUAL("11:11:24+0100", format_iso8601 (moment, false, false, true, true)); } BOOST_AUTO_TEST_CASE(FormatISO8601_TZ) { const time_t moment = 1515492684; - BOOST_CHECK_EQUAL("10:11:24Z+0000", + BOOST_CHECK_EQUAL("10:11:24+0000", format_iso8601 (moment, true, false, true, true)); } @@ -526,14 +526,14 @@ BOOST_AUTO_TEST_CASE(FormatISO8601_DTZ_local) { this->set_tz ("CET"); const time_t moment = 1515492684; - BOOST_CHECK_EQUAL("2018-01-09T11:11:24Z+0100", + BOOST_CHECK_EQUAL("2018-01-09T11:11:24+0100", format_iso8601 (moment, false, true, true, true)); } BOOST_AUTO_TEST_CASE(FormatISO8601_DTZ) { const time_t moment = 1515492684; - BOOST_CHECK_EQUAL("2018-01-09T10:11:24Z+0000", + BOOST_CHECK_EQUAL("2018-01-09T10:11:24+0000", format_iso8601 (moment, true, true, true, true)); } @@ -566,7 +566,7 @@ BOOST_AUTO_TEST_CASE(FormatISO8601_DTZ_struct_tm) helau.tm_gmtoff = 0; helau.tm_zone = NULL; - BOOST_CHECK_EQUAL("2018-11-11T11:11:11Z+0000", + BOOST_CHECK_EQUAL("2018-11-11T11:11:11+0000", format_iso8601 (helau, true, true, true)); } @@ -574,7 +574,7 @@ BOOST_AUTO_TEST_CASE(FormatISO8601_DTZ_struct_timespec) { struct timespec ts = { 1541934671, 11 }; - BOOST_CHECK_EQUAL("2018-11-11T11:11:11Z+0000", + BOOST_CHECK_EQUAL("2018-11-11T11:11:11+0000", format_iso8601 (ts, true, true, true, true)); } @@ -1115,7 +1115,7 @@ BOOST_AUTO_TEST_SUITE(Clock) I2n::clock::Time t (1541934671, 0); boost::optional s = t.format_iso8601 (true, true, true, true); - BOOST_CHECK_EQUAL("2018-11-11T11:11:11Z+0000", *s); + BOOST_CHECK_EQUAL("2018-11-11T11:11:11+0000", *s); } BOOST_AUTO_TEST_CASE(Format_make_nice_time) @@ -1149,8 +1149,8 @@ BOOST_AUTO_TEST_SUITE(Clock) BOOST_AUTO_TEST_CASE(FromString_iso8601_full) { - const std::string in1 ("0001-01-01T00:00:00Z+0000"); - const std::string in2 ("2018-11-11T11:11:11Z+0000"); + const std::string in1 ("0001-01-01T00:00:00+0000"); + const std::string in2 ("2018-11-11T11:11:11+0000"); this->set_utc (); @@ -1170,8 +1170,8 @@ BOOST_AUTO_TEST_SUITE(Clock) BOOST_AUTO_TEST_CASE(FromString_iso8601_full_negyear) { - const std::string in1 ("-0001-01-01T00:00:00Z+0000"); - const std::string in2 ("-2018-11-11T11:11:11Z+0000"); + const std::string in1 ("-0001-01-01T00:00:00+0000"); + const std::string in2 ("-2018-11-11T11:11:11+0000"); this->set_utc (); @@ -1189,6 +1189,23 @@ BOOST_AUTO_TEST_SUITE(Clock) # endif } + BOOST_AUTO_TEST_CASE(FromString_iso8601_Z) + { + const std::string in1 ("2019-04-25T13:41:47+0000"); + const std::string in2 ("2019-04-25T13:41:47Z"); + + this->set_utc (); + boost::optional t1 = I2n::clock::time_of_iso8601 (in1, true, true, true); + boost::optional t2 = I2n::clock::time_of_iso8601 (in2, true, true, true); + + BOOST_CHECK(t1); + BOOST_CHECK(t2); + + BOOST_CHECK_EQUAL(*t1, *t2); + BOOST_CHECK_EQUAL(*t1->format_iso8601 (), *t2->format_iso8601 ()); + BOOST_CHECK_EQUAL(*t2->format_iso8601 (), in1); + } + BOOST_AUTO_TEST_CASE(FromString_iso8601_partial) { const std::string in1 ("2018-11-11T11:11:11");