Parse the YYYY-MM-DDTHH:MM:SSZ dates correctly

Dates in the json reply seem to come in two different formats.
One is the reply timestamp, second one is the actual
content (for example shop opening dates)
This commit is contained in:
King_DuckZ 2020-08-10 21:50:40 +01:00
parent 9bb2efb2ee
commit 417030f4fe

View file

@ -46,8 +46,14 @@ namespace {
//https://howardhinnant.github.io/date/date.html#from_stream_formatting //https://howardhinnant.github.io/date/date.html#from_stream_formatting
Timestamp from_json_timestamp (const std::string& str) { Timestamp from_json_timestamp (const std::string& str) {
if (not str.empty() and str.back() == 'Z') {
//date has this format: 2020-06-19T22:40:51Z
return to_timestamp("%FT%TZ", str);
}
else {
//date has this format: 2020-06-19T22:33:36.855672+00:00 //date has this format: 2020-06-19T22:33:36.855672+00:00
return to_timestamp("%FT%T%Ez", str); return to_timestamp("%FT%T%Ez", str);
}
} }
Timestamp from_header_timestamp (const std::string& str) { Timestamp from_header_timestamp (const std::string& str) {