mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-27 18:10:03 +01:00
Improve parsing of date-only iso8601 strings
This commit is contained in:
parent
9a61fb2c64
commit
db7ddcc195
@ -429,9 +429,20 @@ g_time_val_from_iso8601 (const gchar *iso_date,
|
||||
tm.tm_year = val / 10000 - 1900;
|
||||
}
|
||||
|
||||
if (*iso_date++ != 'T')
|
||||
if (*iso_date != 'T')
|
||||
{
|
||||
/* Date only */
|
||||
if (*iso_date == '\0')
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*iso_date++;
|
||||
|
||||
/* If there is a 'T' then there has to be a time */
|
||||
if (!g_ascii_isdigit (*iso_date))
|
||||
return FALSE;
|
||||
|
||||
|
||||
val = strtoul (iso_date, (char **)&iso_date, 10);
|
||||
if (*iso_date == ':')
|
||||
{
|
||||
|
@ -1283,6 +1283,7 @@ various_string_tests (void)
|
||||
|
||||
#define REF_INVALID1 "Wed Dec 19 17:20:20 GMT 2007"
|
||||
#define REF_INVALID2 "1980-02-22T10:36:00Zulu"
|
||||
#define REF_INVALID3 "1980-02-22T"
|
||||
#define REF_SEC_UTC 320063760
|
||||
#define REF_STR_UTC "1980-02-22T10:36:00Z"
|
||||
#define REF_STR_LOCAL "1980-02-22T13:36:00"
|
||||
@ -1294,6 +1295,7 @@ various_string_tests (void)
|
||||
#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_NST "19800222T070600,0500-0330"
|
||||
#define REF_STR_DATE_ONLY "1980-02-22"
|
||||
|
||||
if (g_test_verbose())
|
||||
g_print ("checking g_time_val_from_iso8601...\n");
|
||||
@ -1301,6 +1303,8 @@ various_string_tests (void)
|
||||
ref_date.tv_usec = 0;
|
||||
g_assert (g_time_val_from_iso8601 (REF_INVALID1, &date) == FALSE);
|
||||
g_assert (g_time_val_from_iso8601 (REF_INVALID2, &date) == FALSE);
|
||||
g_assert (g_time_val_from_iso8601 (REF_INVALID3, &date) == FALSE);
|
||||
g_assert (g_time_val_from_iso8601 (REF_STR_DATE_ONLY, &date) != FALSE);
|
||||
g_assert (g_time_val_from_iso8601 (REF_STR_UTC, &date) != FALSE);
|
||||
if (g_test_verbose())
|
||||
g_print ("\t=> UTC stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
|
||||
|
Loading…
x
Reference in New Issue
Block a user