time/ISO8601: support omitting seconds
This commit is contained in:
parent
2c35ea92bd
commit
f3ed2c0a82
|
@ -133,12 +133,15 @@ ParseISO8601(const char *s)
|
||||||
/* parse the time of day */
|
/* parse the time of day */
|
||||||
if (*s == 'T') {
|
if (*s == 'T') {
|
||||||
++s;
|
++s;
|
||||||
end = strptime(s, "%T", &tm);
|
|
||||||
if (end == nullptr)
|
if ((end = strptime(s, "%T", &tm)) != nullptr)
|
||||||
|
precision = std::chrono::seconds(1);
|
||||||
|
else if ((end = strptime(s, "%H:%M", &tm)) != nullptr)
|
||||||
|
precision = std::chrono::minutes(1);
|
||||||
|
else
|
||||||
throw std::runtime_error("Failed to parse time of day");
|
throw std::runtime_error("Failed to parse time of day");
|
||||||
|
|
||||||
s = end;
|
s = end;
|
||||||
precision = std::chrono::seconds(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto tp = TimeGm(tm);
|
auto tp = TimeGm(tm);
|
||||||
|
|
|
@ -58,6 +58,10 @@ static constexpr struct {
|
||||||
/* without time zone */
|
/* without time zone */
|
||||||
{ "2019-02-04T16:46:41", 1549298801, std::chrono::seconds(1) },
|
{ "2019-02-04T16:46:41", 1549298801, std::chrono::seconds(1) },
|
||||||
|
|
||||||
|
/* without seconds */
|
||||||
|
{ "2019-02-04T16:46", 1549298760, std::chrono::minutes(1) },
|
||||||
|
{ "2019-02-04T16:46Z", 1549298760, std::chrono::minutes(1) },
|
||||||
|
|
||||||
/* with time zone */
|
/* with time zone */
|
||||||
{ "2019-02-04T16:46:41+02", 1549291601, std::chrono::seconds(1) },
|
{ "2019-02-04T16:46:41+02", 1549291601, std::chrono::seconds(1) },
|
||||||
{ "2019-02-04T16:46:41+0200", 1549291601, std::chrono::seconds(1) },
|
{ "2019-02-04T16:46:41+0200", 1549291601, std::chrono::seconds(1) },
|
||||||
|
|
Loading…
Reference in New Issue