Commit efc2cdbf authored by Peter Kjellerstedt's avatar Peter Kjellerstedt Committed by Matthias Clasen

Fix parsing of timezones

Make g_time_val_from_iso8601 handle timezones with minutes correctly;
also accept comma as a fraction separator.  (#578369)
parent d0cf7b38
......@@ -367,7 +367,7 @@ g_time_val_from_iso8601 (const gchar *iso_date,
time_->tv_sec = mktime_utc (&tm);
time_->tv_usec = 0;
if (*iso_date == '.')
if (*iso_date == ',' || *iso_date == '.')
{
glong mul = 100000;
......@@ -382,14 +382,14 @@ g_time_val_from_iso8601 (const gchar *iso_date,
{
gint sign = (*iso_date == '+') ? -1 : 1;
val = 60 * strtoul (iso_date + 1, (char **)&iso_date, 10);
val = strtoul (iso_date + 1, (char **)&iso_date, 10);
if (*iso_date == ':')
val = 60 * val + strtoul (iso_date + 1, (char **)&iso_date, 10);
else
val = 60 * (val / 100) + (val % 100);
time_->tv_sec += (time_t) (val * sign);
time_->tv_sec += (time_t) (60 * val * sign);
}
else if (*iso_date++ != 'Z')
return FALSE;
......
......@@ -1310,10 +1310,12 @@ various_string_tests (void)
#define REF_STR_UTC "1980-02-22T10:36:00Z"
#define REF_STR_CEST "1980-02-22T12:36:00+02:00"
#define REF_STR_EST "19800222T053600-0500"
#define REF_STR_NST "1980-02-22T07:06:00-03:30"
#define REF_USEC_UTC 50000
#define REF_STR_USEC_UTC "1980-02-22T10:36:00.050000Z"
#define REF_STR_USEC_CEST "19800222T123600.050000000+0200"
#define REF_STR_USEC_EST "1980-02-22T05:36:00.05-05:00"
#define REF_STR_USEC_EST "1980-02-22T05:36:00,05-05:00"
#define REF_STR_USEC_NST "19800222T070600,0500-0330"
if (g_test_verbose())
g_print ("checking g_time_val_from_iso8601...\n");
......@@ -1342,6 +1344,13 @@ various_string_tests (void)
date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
g_assert (g_time_val_from_iso8601 (REF_STR_NST, &date) != FALSE);
if (g_test_verbose())
g_print ("\t=> NST stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
ref_date.tv_usec = REF_USEC_UTC;
g_assert (g_time_val_from_iso8601 (REF_STR_USEC_UTC, &date) != FALSE);
if (g_test_verbose())
......@@ -1364,6 +1373,13 @@ various_string_tests (void)
date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
g_assert (g_time_val_from_iso8601 (REF_STR_USEC_NST, &date) != FALSE);
if (g_test_verbose())
g_print ("\t=> NST stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
if (g_test_verbose())
g_print ("checking g_time_val_to_iso8601...\n");
ref_date.tv_sec = REF_SEC_UTC;
......
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