Commit 54195895 authored by Bastien Nocera's avatar Bastien Nocera

plparser: Remove use of Y2038 unsafe GTimeVal

Use GDateTime instead.

g_date_time_new_from_iso8601() was added in glib 2.56, so bump the
requirements.

Note that this also changes one of the tests, as GDateTime does not
support leap seconds as the old GTimeVal code used to do.

See glib#1938
parent 019cb6a7
......@@ -30,7 +30,7 @@ plparse_soversion = plparse_lt_current - plparse_lt_age
plparse_libversion = '@0@.@1@.@2@'.format(plparse_soversion, plparse_lt_age, plparse_lt_revision)
# Requirements
glib_req = '>= 2.36.0'
glib_req = '>= 2.56.0'
gio_req = '>= 2.24.0'
quvi_req = '>= 0.9.1'
archive_req = '>= 3.0'
......
......@@ -135,7 +135,7 @@ test_date (void)
/* Atom */
g_assert_cmpuint (totem_pl_parser_parse_date ("2003-12-13T18:30:02Z", verbose), ==, 1071340202);
g_assert_cmpuint (totem_pl_parser_parse_date ("1990-12-31T15:59:60-08:00", verbose), ==, 662688000);
g_assert_cmpuint (totem_pl_parser_parse_date ("1990-12-31T15:59:59-08:00", verbose), ==, 662687999);
}
#define READ_CHUNK_SIZE 8192
......
......@@ -2361,27 +2361,24 @@ totem_pl_parser_parse_duration (const char *duration, gboolean debug)
guint64
totem_pl_parser_parse_date (const char *date_str, gboolean debug)
{
GTimeVal val;
g_autoptr(GDateTime) date = NULL;
g_return_val_if_fail (date_str != NULL, -1);
memset (&val, 0, sizeof(val));
/* Try to parse as an ISO8601/RFC3339 date */
if (g_time_val_from_iso8601 (date_str, &val) != FALSE) {
date = g_date_time_new_from_iso8601 (date_str, NULL);
if (date != NULL) {
D(g_message ("Parsed duration '%s' using the ISO8601 parser", date_str));
return val.tv_sec;
return g_date_time_to_unix (date);
}
D(g_message ("Failed to parse duration '%s' using the ISO8601 parser", date_str));
/* Fall back to RFC 2822 date parsing */
{
g_autoptr(GDateTime) date = NULL;
date = g_mime_utils_header_decode_date (date_str);
if (!date || !g_date_time_to_timeval (date, &val)) {
D(g_message ("Failed to parse duration '%s' using the RFC 2822 parser", date_str));
return -1;
}
return val.tv_sec;
date = g_mime_utils_header_decode_date (date_str);
if (!date) {
D(g_message ("Failed to parse duration '%s' using the RFC 2822 parser", date_str));
return -1;
}
return g_date_time_to_unix (date);
}
#endif /* !TOTEM_PL_PARSER_MINI */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment