[evolution-data-server] Add camel_mktime_utc() and camel_localtime_with_offset().



commit d0845eb2c007ea978d00c5c8800697b9842ae8de
Author: Matthew Barnes <mbarnes redhat com>
Date:   Mon Nov 14 19:13:27 2011 -0500

    Add camel_mktime_utc() and camel_localtime_with_offset().
    
    Copied from libedataserver/e-time-utils.c.

 camel/camel-mime-message.c               |    4 +-
 camel/camel-mime-utils.c                 |   71 ++++++++++++++++++++++++++++--
 camel/camel-mime-utils.h                 |    6 +++
 camel/providers/imap/camel-imap-folder.c |    4 +-
 docs/reference/camel/camel-sections.txt  |    2 +
 5 files changed, 77 insertions(+), 10 deletions(-)
---
diff --git a/camel/camel-mime-message.c b/camel/camel-mime-message.c
index 24f0558..72e4328 100644
--- a/camel/camel-mime-message.c
+++ b/camel/camel-mime-message.c
@@ -32,8 +32,6 @@
 #include <stdio.h>
 #include <string.h>
 
-#include <libedataserver/e-time-utils.h>
-
 #include "camel-iconv.h"
 #include "camel-mime-filter-bestenc.h"
 #include "camel-mime-filter-charset.h"
@@ -434,7 +432,7 @@ camel_mime_message_set_date (CamelMimeMessage *message,
 		gint tz;
 
 		date = time (NULL);
-		e_localtime_with_offset (date, &local, &tz);
+		camel_localtime_with_offset (date, &local, &tz);
 		offset = (((tz / 60 / 60) * 100) + (tz / 60 % 60));
 	}
 	message->date = date;
diff --git a/camel/camel-mime-utils.c b/camel/camel-mime-utils.c
index 43688be..543631f 100644
--- a/camel/camel-mime-utils.c
+++ b/camel/camel-mime-utils.c
@@ -41,8 +41,6 @@
 #define MAXHOSTNAMELEN 1024
 #endif
 
-#include <libedataserver/e-time-utils.h>
-
 #include "camel-charset-map.h"
 #include "camel-iconv.h"
 #include "camel-mime-utils.h"
@@ -71,6 +69,71 @@
 #define d(x)
 #define d2(x)
 
+/**
+ * camel_mktime_utc:
+ * @tm: the #tm to convert to a calendar time representation
+ *
+ * Like mktime(3), but assumes UTC instead of local timezone.
+ *
+ * Returns: the calendar time representation of @tm
+ *
+ * Since: 3.4
+ **/
+time_t
+camel_mktime_utc (struct tm *tm)
+{
+	time_t tt;
+
+	tm->tm_isdst = -1;
+	tt = mktime (tm);
+
+#if defined (HAVE_TM_GMTOFF)
+	tt += tm->tm_gmtoff;
+#elif defined (HAVE_TIMEZONE)
+	if (tm->tm_isdst > 0) {
+#if defined (HAVE_ALTZONE)
+		tt -= altzone;
+#else
+		tt -= (timezone - 3600);
+#endif
+	} else
+		tt -= timezone;
+#endif
+
+	return tt;
+}
+
+/**
+ * camel_localtime_with_offset:
+ * @tt: the #time_t to convert
+ * @tm: the #tm to store the result in
+ * @offset: the #gint to store the offset in
+ *
+ * Converts the calendar time representation @tt to a broken-down
+ * time representation, stored in @tm, and provides the offset in
+ * seconds from UTC time, stored in @offset.
+ **/
+void
+camel_localtime_with_offset (time_t tt,
+                             struct tm *tm,
+                             gint *offset)
+{
+	localtime_r (&tt, tm);
+
+#if defined (HAVE_TM_GMTOFF)
+	*offset = tm->tm_gmtoff;
+#elif defined (HAVE_TIMEZONE)
+	if (tm->tm_isdst > 0) {
+#if defined (HAVE_ALTZONE)
+		*offset = -altzone;
+#else
+		*offset = -(timezone - 3600);
+#endif
+	} else
+		*offset = -timezone;
+#endif
+}
+
 #define CAMEL_UUENCODE_CHAR(c)  ((c) ? (c) + ' ' : '`')
 #define	CAMEL_UUDECODE_CHAR(c)	(((c) - ' ') & 077)
 
@@ -4089,7 +4152,7 @@ parse_rfc822_date (struct _date_token *tokens,
 		offset = n;
 	}
 
-	t = e_mktime_utc (&tm);
+	t = camel_mktime_utc (&tm);
 
 	/* t is now GMT of the time we want, but not offset by the timezone ... */
 
@@ -4217,7 +4280,7 @@ parse_broken_date (struct _date_token *tokens,
 
 	d(printf ("\n"));
 
-	t = e_mktime_utc (&tm);
+	t = camel_mktime_utc (&tm);
 
 	/* t is now GMT of the time we want, but not offset by the timezone ... */
 
diff --git a/camel/camel-mime-utils.h b/camel/camel-mime-utils.h
index 392dc9c..a207a0b 100644
--- a/camel/camel-mime-utils.h
+++ b/camel/camel-mime-utils.h
@@ -101,6 +101,12 @@ struct _camel_header_newsgroup {
 	gchar *newsgroup;
 };
 
+/* Time utilities */
+time_t		camel_mktime_utc		(struct tm *tm);
+void		camel_localtime_with_offset	(time_t tt,
+						 struct tm *tm,
+						 gint *offset);
+
 /* Address lists */
 struct _camel_header_address *camel_header_address_new (void);
 struct _camel_header_address *camel_header_address_new_name (const gchar *name, const gchar *addr);
diff --git a/camel/providers/imap/camel-imap-folder.c b/camel/providers/imap/camel-imap-folder.c
index 4ca38ba..28fdf01 100644
--- a/camel/providers/imap/camel-imap-folder.c
+++ b/camel/providers/imap/camel-imap-folder.c
@@ -36,8 +36,6 @@
 
 #include <glib/gi18n-lib.h>
 
-#include <libedataserver/e-time-utils.h>
-
 #include <camel/camel.h>
 
 #include "camel-imap-command.h"
@@ -3777,7 +3775,7 @@ decode_internaldate (const guchar *in)
 
 	n = strtol ((gchar *) inptr, NULL, 10);
 
-	date = e_mktime_utc (&tm);
+	date = camel_mktime_utc (&tm);
 
 	/* date is now GMT of the time we want, but not offset by the timezone ... */
 
diff --git a/docs/reference/camel/camel-sections.txt b/docs/reference/camel/camel-sections.txt
index bab85b1..802fa3a 100644
--- a/docs/reference/camel/camel-sections.txt
+++ b/docs/reference/camel/camel-sections.txt
@@ -2852,6 +2852,8 @@ CAMEL_UUDECODE_STATE_INIT
 CAMEL_UUDECODE_STATE_BEGIN
 CAMEL_UUDECODE_STATE_END
 CAMEL_UUDECODE_STATE_MASK
+camel_mktime_utc
+camel_localtime_with_offset
 CamelTransferEncoding
 camel_header_references
 camel_header_param



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]