|
22 | 22 | #define _GNU_SOURCE |
23 | 23 | #endif |
24 | 24 | #include "gps_parser.h" |
| 25 | +#include <QDateTime> |
| 26 | +#include <QTimeZone> |
25 | 27 |
|
26 | 28 | #define _x (const xmlChar *) |
27 | 29 | #define _s (const char *) |
@@ -70,36 +72,25 @@ double get_avg_gps_time_ms(gps_private_data gdata) |
70 | 72 | */ |
71 | 73 | int64_t datetimeXMLstring_to_mseconds(const char *text, char *format /* = NULL*/) |
72 | 74 | { |
73 | | - char def_format[] = "%Y-%m-%dT%H:%M:%S"; |
74 | 75 | int64_t ret = 0; |
75 | | - int ms = 0; |
76 | | - struct tm tm_time; |
77 | | - //samples: 2020-07-11T09:03:23.000Z or 2021-02-27T12:10:00+00:00 |
78 | | - tm_time.tm_isdst = -1; //force dst detection |
79 | 76 |
|
80 | | - if (format == NULL) |
81 | | - format = def_format; |
| 77 | + QDateTime datetime; |
| 78 | + if (format != NULL) |
| 79 | + datetime = QDateTime::fromString(QString(text), QString(format)); |
| 80 | + else |
| 81 | + datetime = QDateTime::fromString(QString(text), Qt::ISODateWithMs); |
82 | 82 |
|
83 | | - if (strptime(text, format, &tm_time) == NULL) { |
| 83 | + if (!datetime.isValid()) { |
84 | 84 | mlt_log_warning( |
85 | 85 | NULL, |
86 | | - "filter_gpsText.c datetimeXMLstring_to_seconds strptime failed on string: %.25s", |
| 86 | + "filter_gpsText.c datetimeXMLstring_to_seconds conversion failed on string: %.25s", |
87 | 87 | text); |
88 | 88 | return 0; |
89 | 89 | } |
90 | 90 |
|
91 | | - ret = internal_timegm(&tm_time); |
92 | | - |
93 | | - //check if we have miliseconds, 3 digits only |
94 | | - const char *ms_part = strchr(text, '.'); |
95 | | - if (ms_part != NULL) { |
96 | | - ms = strtol(ms_part + 1, NULL, 10); |
97 | | - while (abs(ms) > 999) |
98 | | - ms /= 10; |
99 | | - } |
100 | | - ret = ret * 1000 + ms; |
| 91 | + datetime.setTimeZone(QTimeZone::UTC); |
101 | 92 |
|
102 | | - // mlt_log_info(NULL, "datetimeXMLstring_to_mseconds: text:%s, ms:%d (/1000)", text, ret/1000); |
| 93 | + ret = datetime.toMSecsSinceEpoch(); |
103 | 94 | return ret; |
104 | 95 | } |
105 | 96 |
|
|
0 commit comments