diff options
author | Nicolas Dufresne <nicolas.dufresne@collabora.co.uk> | 2011-03-03 15:35:14 -0500 |
---|---|---|
committer | Nicolas Dufresne <nicolas.dufresne@collabora.co.uk> | 2011-03-03 15:44:50 -0500 |
commit | fe3fcdc701e7ee091a10dcbe82af55ce3a7d14b5 (patch) | |
tree | 2737f05aa8306fa07e8c2a074ffe4f43613345db /telepathy-logger/util.c | |
parent | 968941a7c7d417b58743c19145a37beceeb6e2be (diff) | |
download | telepathy-logger-fe3fcdc701e7ee091a10dcbe82af55ce3a7d14b5.tar.gz |
Move _time_parse() to util and remove datetime
Diffstat (limited to 'telepathy-logger/util.c')
-rw-r--r-- | telepathy-logger/util.c | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/telepathy-logger/util.c b/telepathy-logger/util.c index c14c865..d242972 100644 --- a/telepathy-logger/util.c +++ b/telepathy-logger/util.c @@ -1,6 +1,7 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* - * Copyright (C) 2009 Collabora Ltd. + * Copyright (C) 2009-2011 Collabora Ltd. + * Copyright (C) 2003-2007 Imendio AB * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -17,6 +18,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * Authors: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> + * Richard Hult <richard@imendio.com> */ #include "util-internal.h" @@ -91,3 +93,34 @@ _tpl_rmdir_recursively (const gchar *dir_name) dir_name, g_strerror (errno)); } + +/* The format is: "20021209T23:51:30" and is in UTC. 0 is returned on + * failure. The alternative format "20021209" is also accepted. + */ +gint64 +_tpl_time_parse (const gchar *str) +{ + gint year = 0; + gint month = 0; + gint day = 0; + gint hour = 0; + gint min = 0; + gint sec = 0; + gint n_parsed; + GDateTime *dt; + gint64 ts; + + n_parsed = sscanf (str, "%4d%2d%2dT%2d:%2d:%2d", + &year, &month, &day, &hour, + &min, &sec); + + if (n_parsed != 3 && n_parsed != 6) + return 0; + + dt = g_date_time_new_utc (year, month, day, hour, min, sec); + ts = g_date_time_to_unix (dt); + + g_date_time_unref (dt); + + return ts; +} |