Showing the changes to Source/Libraries/TimeSeriesPlatformLibrary/Common/Convert.cpp (1 of 3 files). Show all
Unified · Split
| @@ -188,6 +188,49 @@ const char* GSF::TimeSeries::Coalesce(const char* data, const char* nonEmptyValu · 187 unmodified lines | ||
| 188 | 188 | return data; |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | +time_t GSF::TimeSeries::ParseTimestamp(const char* time) | |
| 192 | +{ | |
| 193 | + // Need a "generic" ParseTimestamp function... | |
| 194 | +// istringstream in { time }; | |
| 195 | +// sys_seconds timestamp; | |
| 196 | +// | |
| 197 | +// // Try parsing several date-time formats formatted timestamp string | |
| 198 | +// // using the Hinnant date library: https://github.com/HowardHinnant/date | |
| 199 | +// | |
| 200 | +// // Need to try several date/time format variations per: | |
| 201 | +// // https://howardhinnant.github.io/date/date.html#from_stream_formatting | |
| 202 | +// /* | |
| 203 | +// istringstream in { "2018-01-12 12:05:14" }; | |
| 204 | +// sys_seconds timestamp; | |
| 205 | +// | |
| 206 | +// in >> parse("%Y-%m-%dT%T%z", timestamp); | |
| 207 | +// | |
| 208 | +// if (bool(in)) | |
| 209 | +// { | |
| 210 | +// std::cout << "Parsed XML time: " << system_clock::to_time_t(timestamp) << "\n"; | |
| 211 | +// } | |
| 212 | +// else | |
| 213 | +// { | |
| 214 | +// in.clear(); | |
| 215 | +// in.str("2018-01-12 12:05:14"); | |
| 216 | +// in >> parse("%F%n %T", timestamp); | |
| 217 | +// | |
| 218 | +// if (bool(in)) | |
| 219 | +// { | |
| 220 | +// std::cout << "Parsed std time: " << system_clock::to_time_t(timestamp) << "\n"; | |
| 221 | +// } | |
| 222 | +// else | |
| 223 | +// { | |
| 224 | +// std::cout << "Failed to parse time...\n"; | |
| 225 | +// } | |
| 226 | +// } | |
| 227 | +// */ | |
| 228 | +// | |
| 229 | +// // Try XML format, e.g.: 2018-03-14T19:23:11.665-04:00: | |
| 230 | +// in >> parse("%Y-%m-%dT%T%z", timestamp); | |
| 231 | + return ParseXMLTimestamp(time); | |
| 232 | +} | |
| 233 | + | |
| 191 | 234 | time_t GSF::TimeSeries::ParseXMLTimestamp(const char* time) |
| 192 | 235 | { |
| 193 | 236 | istringstream in { time }; |
| @@ -198,4 +241,4 @@ time_t GSF::TimeSeries::ParseXMLTimestamp(const char* time) · 4 unmodified lines | ||
| 198 | 241 | in >> parse("%Y-%m-%dT%T%z", timestamp); |
| 199 | 242 | |
| 200 | 243 | return system_clock::to_time_t(timestamp); |
| 201 | −} | |
| 244 | +} | |