Skip to content

Commit 4e4dc09

Browse files
committed
Get rid of strptime
strptime is not portable as it is not supported by MinGW and MSVC. We only use it for the GPS filters which use Qt anyways hence we can use QDateTime instead.
1 parent 6429947 commit 4e4dc09

8 files changed

Lines changed: 15 additions & 628 deletions

File tree

.github/workflows/static-code-analysis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ jobs:
1414
-i src/modules/glaxnimate/glaxnimate/
1515
-i src/modules/plus/ebur128/
1616
-i src/modules/xml/common.c
17-
-i src/win32/strptime.c
1817
--include=src/framework/mlt_log.h
1918
--include=src/framework/mlt_types.h
2019
--library=cppcheck.cfg

makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ cppcheck:
2525
-i src/modules/glaxnimate/glaxnimate/ \
2626
-i src/modules/plus/ebur128/ \
2727
-i src/modules/xml/common.c \
28-
-i src/win32/strptime.c \
2928
--include=src/framework/mlt_log.h \
3029
--include=src/framework/mlt_types.h \
3130
--library=cppcheck.cfg \

src/framework/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ if(WIN32)
111111
target_link_options(mlt PRIVATE -Wl,--output-def,${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/libmlt-${MLT_VERSION_MAJOR}.def)
112112
install(FILES "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/libmlt-${MLT_VERSION_MAJOR}.def" DESTINATION ${CMAKE_INSTALL_LIBDIR})
113113
endif()
114-
target_sources(mlt PRIVATE ../win32/win32.c ../win32/strptime.c)
114+
target_sources(mlt PRIVATE ../win32/win32.c)
115115
target_link_libraries(mlt PRIVATE Iconv::Iconv)
116116
if(NOT WINDOWS_DEPLOY)
117117
target_compile_definitions(mlt PRIVATE NODEPLOY)

src/framework/mlt_types.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,6 @@ MLT_EXPORT FILE *win32_fopen(const char *filename_utf8, const char *mode_utf8);
346346
#include <sys/types.h>
347347
MLT_EXPORT int win32_stat(const char *filename_utf8, struct stat *buffer);
348348
#include <time.h>
349-
MLT_EXPORT char *strptime(const char *buf, const char *fmt, struct tm *tm);
350349
#define mlt_fopen win32_fopen
351350
#define mlt_stat win32_stat
352351
#define MLT_DIRLIST_DELIMITER ";"

src/modules/qt/filter_gpstext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ static void process_filter_properties(mlt_filter filter, mlt_frame frame)
425425
if (strlen(read_gps_processing_start_time) != 0
426426
&& strcmp(read_gps_processing_start_time, "yyyy-MM-dd hh:mm:ss"))
427427
gps_proc_t = datetimeXMLstring_to_mseconds(read_gps_processing_start_time,
428-
(char *) "%Y-%m-%d %H:%M:%S");
428+
(char *) "yyyy-MM-dd hh:mm:ss");
429429
if (gps_proc_t != pdata->gps_proc_start_t) {
430430
pdata->gps_proc_start_t = gps_proc_t;
431431
do_processing = 1;

src/modules/qt/gps_parser.cpp

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#define _GNU_SOURCE
2323
#endif
2424
#include "gps_parser.h"
25+
#include <QDateTime>
26+
#include <QTimeZone>
2527

2628
#define _x (const xmlChar *)
2729
#define _s (const char *)
@@ -70,36 +72,25 @@ double get_avg_gps_time_ms(gps_private_data gdata)
7072
*/
7173
int64_t datetimeXMLstring_to_mseconds(const char *text, char *format /* = NULL*/)
7274
{
73-
char def_format[] = "%Y-%m-%dT%H:%M:%S";
7475
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
7976

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);
8282

83-
if (strptime(text, format, &tm_time) == NULL) {
83+
if (!datetime.isValid()) {
8484
mlt_log_warning(
8585
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",
8787
text);
8888
return 0;
8989
}
9090

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);
10192

102-
// mlt_log_info(NULL, "datetimeXMLstring_to_mseconds: text:%s, ms:%d (/1000)", text, ret/1000);
93+
ret = datetime.toMSecsSinceEpoch();
10394
return ret;
10495
}
10596

src/tests/test_mod_qt_gps/test_mod_qt_gps.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private Q_SLOTS:
6363

6464
// Unknown input, with format string as hint
6565
const char *text = "12:10:00 27-02-2021";
66-
gps_proc_t = datetimeXMLstring_to_mseconds(text, (char *) "%H:%M:%S %d-%m-%Y");
66+
gps_proc_t = datetimeXMLstring_to_mseconds(text, (char *) "HH:mm:ss dd-MM-yyyy");
6767
QCOMPARE(gps_proc_t, 1614427800000);
6868

6969
// Unknown input, without format string
@@ -73,7 +73,7 @@ private Q_SLOTS:
7373

7474
// Valid input, but mismatching format string
7575
text = "2021-02-27T12:10:00+00:00";
76-
gps_proc_t = datetimeXMLstring_to_mseconds(text, (char *) "%H:%M:%S %d-%m-%Y");
76+
gps_proc_t = datetimeXMLstring_to_mseconds(text, (char *) "HH:mm:ss dd-MM-yyyy");
7777
QCOMPARE(gps_proc_t, 0);
7878
}
7979

0 commit comments

Comments
 (0)