summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Dufresne <nicolas.dufresne@collabora.co.uk>2011-03-03 15:35:14 -0500
committerNicolas Dufresne <nicolas.dufresne@collabora.co.uk>2011-03-03 15:44:50 -0500
commitfe3fcdc701e7ee091a10dcbe82af55ce3a7d14b5 (patch)
tree2737f05aa8306fa07e8c2a074ffe4f43613345db
parent968941a7c7d417b58743c19145a37beceeb6e2be (diff)
downloadtelepathy-logger-fe3fcdc701e7ee091a10dcbe82af55ce3a7d14b5.tar.gz
Move _time_parse() to util and remove datetime
-rw-r--r--doc/reference/libtelepathy-logger/Makefile.am1
-rw-r--r--telepathy-logger/Makefile.am2
-rw-r--r--telepathy-logger/datetime-internal.h42
-rw-r--r--telepathy-logger/datetime.c109
-rw-r--r--telepathy-logger/log-manager.c1
-rw-r--r--telepathy-logger/log-store-pidgin.c1
-rw-r--r--telepathy-logger/log-store-xml.c1
-rw-r--r--telepathy-logger/text-channel.c1
-rw-r--r--telepathy-logger/util-internal.h6
-rw-r--r--telepathy-logger/util.c35
10 files changed, 39 insertions, 160 deletions
diff --git a/doc/reference/libtelepathy-logger/Makefile.am b/doc/reference/libtelepathy-logger/Makefile.am
index c235d1f..8a00623 100644
--- a/doc/reference/libtelepathy-logger/Makefile.am
+++ b/doc/reference/libtelepathy-logger/Makefile.am
@@ -61,7 +61,6 @@ IGNORE_HFILES=\
channel-internal.h \
conf-internal.h \
contact-internal.h \
- datetime-internal.h \
dbus-service-internal.h \
debug-internal.h \
event-internal.h \
diff --git a/telepathy-logger/Makefile.am b/telepathy-logger/Makefile.am
index 7431e92..9941f7b 100644
--- a/telepathy-logger/Makefile.am
+++ b/telepathy-logger/Makefile.am
@@ -52,8 +52,6 @@ libtelepathy_logger_la_SOURCES = \
conf-internal.h \
entity.c \
entity-internal.h \
- datetime.c \
- datetime-internal.h \
dbus-service.c \
dbus-service-internal.h \
debug-internal.h \
diff --git a/telepathy-logger/datetime-internal.h b/telepathy-logger/datetime-internal.h
deleted file mode 100644
index 481c624..0000000
--- a/telepathy-logger/datetime-internal.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * Copyright (C) 2004 Imendio AB
- * Copyright (C) 2007-2010 Collabora Ltd.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Authors: Richard Hult <richard@imendio.com>
- */
-
-#ifndef __TPL_TIME_H__
-#define __TPL_TIME_H__
-
-#ifndef __USE_XOPEN
-#define __USE_XOPEN
-#endif
-#include <time.h>
-
-#include <glib.h>
-
-G_BEGIN_DECLS
-#define _TPL_TIME_FORMAT_DISPLAY_SHORT "%H:%M"
-#define _TPL_TIME_FORMAT_DISPLAY_LONG "%a %d %b %Y"
-time_t _tpl_time_get_current (void);
-gint64 _tpl_time_parse (const gchar * str);
-gchar *_tpl_time_to_string_utc (time_t t, const gchar * format);
-gchar *_tpl_time_to_string_local (time_t t, const gchar * format);
-
-G_END_DECLS
-#endif /* __TPL_TIME_H__ */
diff --git a/telepathy-logger/datetime.c b/telepathy-logger/datetime.c
deleted file mode 100644
index d4f6391..0000000
--- a/telepathy-logger/datetime.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * Copyright (C) 2003-2007 Imendio AB
- * Copyright (C) 2007-2010 Collabora Ltd.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Authors: Richard Hult <richard@imendio.com>
- */
-
-#include "config.h"
-#include "datetime-internal.h"
-
-#include <glib/gi18n.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-
-
-/* Note: time is always in UTC. */
-
-time_t
-_tpl_time_get_current (void)
-{
- return time (NULL);
-}
-
-
-/* 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;
-}
-
-/* Converts the UTC timestamp to a string, also in UTC. Returns NULL on failure. */
-gchar *
-_tpl_time_to_string_utc (time_t t,
- const gchar * format)
-{
- gchar stamp[128];
- struct tm *tm;
-
- g_return_val_if_fail (format != NULL, NULL);
-
- tm = gmtime (&t);
- if (strftime (stamp, sizeof (stamp), format, tm) == 0)
- {
- return NULL;
- }
-
- return g_strdup (stamp);
-}
-
-/* Converts the UTC timestamp to a string, in local time. Returns NULL on failure. */
-gchar *
-_tpl_time_to_string_local (time_t t,
- const gchar *format)
-{
- gchar stamp[128];
- struct tm *tm;
-
- g_return_val_if_fail (format != NULL, NULL);
-
- tm = localtime (&t);
- if (strftime (stamp, sizeof (stamp), format, tm) == 0)
- {
- return NULL;
- }
-
- return g_strdup (stamp);
-}
diff --git a/telepathy-logger/log-manager.c b/telepathy-logger/log-manager.c
index a69a4f9..00229c4 100644
--- a/telepathy-logger/log-manager.c
+++ b/telepathy-logger/log-manager.c
@@ -43,7 +43,6 @@
#include <telepathy-logger/log-store-sqlite-internal.h>
#define DEBUG_FLAG TPL_DEBUG_LOG_MANAGER
-#include <telepathy-logger/datetime-internal.h>
#include <telepathy-logger/debug-internal.h>
#include <telepathy-logger/util-internal.h>
diff --git a/telepathy-logger/log-store-pidgin.c b/telepathy-logger/log-store-pidgin.c
index 766f724..b40a214 100644
--- a/telepathy-logger/log-store-pidgin.c
+++ b/telepathy-logger/log-store-pidgin.c
@@ -35,7 +35,6 @@
#include "log-manager-internal.h"
#include "text-event-internal.h"
#include "entity-internal.h"
-#include "datetime-internal.h"
#include "util-internal.h"
#define DEBUG_FLAG TPL_DEBUG_LOG_STORE
diff --git a/telepathy-logger/log-store-xml.c b/telepathy-logger/log-store-xml.c
index 84be52c..7486e90 100644
--- a/telepathy-logger/log-store-xml.c
+++ b/telepathy-logger/log-store-xml.c
@@ -49,7 +49,6 @@
#define DEBUG_FLAG TPL_DEBUG_LOG_STORE
#include <telepathy-logger/entity-internal.h>
-#include <telepathy-logger/datetime-internal.h>
#include <telepathy-logger/debug-internal.h>
#include <telepathy-logger/util-internal.h>
diff --git a/telepathy-logger/text-channel.c b/telepathy-logger/text-channel.c
index 67b9a5b..b34ae2c 100644
--- a/telepathy-logger/text-channel.c
+++ b/telepathy-logger/text-channel.c
@@ -38,7 +38,6 @@
#define DEBUG_FLAG TPL_DEBUG_CHANNEL
#include <telepathy-logger/action-chain-internal.h>
#include <telepathy-logger/entity-internal.h>
-#include <telepathy-logger/datetime-internal.h>
#include <telepathy-logger/debug-internal.h>
#include <telepathy-logger/util-internal.h>
diff --git a/telepathy-logger/util-internal.h b/telepathy-logger/util-internal.h
index e5d75cf..3c7982e 100644
--- a/telepathy-logger/util-internal.h
+++ b/telepathy-logger/util-internal.h
@@ -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>
*/
#ifndef __TPL_UTIL_H__
@@ -32,5 +34,7 @@ gchar *_tpl_create_message_token (const gchar *channel, gint64 timestamp,
void _tpl_rmdir_recursively (const gchar *dir_name);
+gint64 _tpl_time_parse (const gchar * str);
+
#endif // __TPL_UTIL_H__
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;
+}