summaryrefslogtreecommitdiff
path: root/glib/gtimer.c
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2008-07-21 13:05:24 +0000
committerEmmanuele Bassi <ebassi@src.gnome.org>2008-07-21 13:05:24 +0000
commitbcdc09e641b471a2e3f809b1248bd40fd64995de (patch)
tree4c19556b29841ee43fc20b04dae96f6beec1eead /glib/gtimer.c
parentf573de59d2686399c68a6e2ad58d85aed8b8cd47 (diff)
downloadglib-bcdc09e641b471a2e3f809b1248bd40fd64995de.tar.gz
Do not set the timestamp value using time(), as it will be overwritten
2008-07-21 Emmanuele Bassi <ebassi@gnome.org> * glib/gbookmarkfile.c: (bookmark_app_info_new): Do not set the timestamp value using time(), as it will be overwritten anyway. (#535223, Michael Meeks) (parse_application_element), (bookmark_app_info_dump): Support the "modified" attribute, which takes an ISO-formatted string instead of a Unix time stamp, to keep the number of g_strdup_printf() calls to a minimum. * glib/gtimer.c: (g_time_val_to_iso8601): Do not use strftime(): we know the format and contents of the ISO 8601 date format we use. * tests/bookmarks/valid-03.xbel: Add a test file for the modified attribute. svn path=/trunk/; revision=7231
Diffstat (limited to 'glib/gtimer.c')
-rw-r--r--glib/gtimer.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/glib/gtimer.c b/glib/gtimer.c
index b75730ac4..8a1f7f25d 100644
--- a/glib/gtimer.c
+++ b/glib/gtimer.c
@@ -430,20 +430,30 @@ g_time_val_to_iso8601 (GTimeVal *time_)
if (time_->tv_usec != 0)
{
-#define ISO_8601_FRAC_LEN 28
-#define ISO_8601_FRAC_FORMAT "%%Y-%%m-%%dT%%H:%%M:%%S.%06ldZ"
- gchar *format = g_strdup_printf (ISO_8601_FRAC_FORMAT, time_->tv_usec);
-
- retval = g_new0 (gchar, ISO_8601_FRAC_LEN + 1);
- strftime (retval, ISO_8601_FRAC_LEN, format, tm);
- g_free (format);
+ /* ISO 8601 date and time format, with fractionary seconds:
+ * YYYY-MM-DDTHH:MM:SS.MMMMMMZ
+ */
+ retval = g_strdup_printf ("%d-%d-%dT%d:%d:%d.%06ldZ",
+ tm->tm_year + 1900,
+ tm->tm_mon + 1,
+ tm->tm_mday,
+ tm->tm_hour,
+ tm->tm_min,
+ tm->tm_sec,
+ time_->tv_usec);
}
else
{
-#define ISO_8601_LEN 21
-#define ISO_8601_FORMAT "%Y-%m-%dT%H:%M:%SZ"
- retval = g_new0 (gchar, ISO_8601_LEN + 1);
- strftime (retval, ISO_8601_LEN, ISO_8601_FORMAT, tm);
+ /* ISO 8601 date and time format:
+ * YYYY-MM-DDTHH:MM:SSZ
+ */
+ retval = g_strdup_printf ("%d-%d-%dT%d:%d:%dZ",
+ tm->tm_year + 1900,
+ tm->tm_mon + 1,
+ tm->tm_mday,
+ tm->tm_hour,
+ tm->tm_min,
+ tm->tm_sec);
}
return retval;