aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2010-04-08 01:27:42 +0100
committerWilmer van der Gaast <wilmer@gaast.net>2010-04-08 01:27:42 +0100
commit2e3a8576d6ca511df347426b4319bccde1871d06 (patch)
tree58741cbd88805176701a1ff8b1fc6b635a4cd546
parent91cec2ff02f956ec248dae6c8b8939f263ff8cfd (diff)
Added a mktime_utc() to misc.c using code that used to be in jabber_util.c.
I want to use this in the Twitter module.
-rw-r--r--lib/misc.c35
-rw-r--r--lib/misc.h1
-rw-r--r--protocols/jabber/jabber_util.c29
3 files changed, 39 insertions, 26 deletions
diff --git a/lib/misc.c b/lib/misc.c
index fe2ff17c..1d36d639 100644
--- a/lib/misc.c
+++ b/lib/misc.c
@@ -78,6 +78,41 @@ time_t get_time(int year, int month, int day, int hour, int min, int sec)
return mktime(&tm);
}
+time_t mktime_utc( struct tm *tp )
+{
+ struct tm utc;
+ time_t res, tres;
+
+ tp->tm_isdst = -1;
+ res = mktime( tp );
+ /* Problem is, mktime() just gave us the GMT timestamp for the
+ given local time... While the given time WAS NOT local. So
+ we should fix this now.
+
+ Now I could choose between messing with environment variables
+ (kludgy) or using timegm() (not portable)... Or doing the
+ following, which I actually prefer...
+
+ tzset() may also work but in other places I actually want to
+ use local time.
+
+ FFFFFFFFFFFFFFFFFFFFFUUUUUUUUUUUUUUUUUUUU!! */
+ gmtime_r( &res, &utc );
+ utc.tm_isdst = -1;
+ if( utc.tm_hour == tp->tm_hour && utc.tm_min == tp->tm_min )
+ /* Sweet! We're in UTC right now... */
+ return res;
+
+ tres = mktime( &utc );
+ res += res - tres;
+
+ /* Yes, this is a hack. And it will go wrong around DST changes.
+ BUT this is more likely to be threadsafe than messing with
+ environment variables, and possibly more portable... */
+
+ return res;
+}
+
typedef struct htmlentity
{
char code[7];
diff --git a/lib/misc.h b/lib/misc.h
index ce36caf5..9f2058b6 100644
--- a/lib/misc.h
+++ b/lib/misc.h
@@ -42,6 +42,7 @@ G_MODULE_EXPORT char *add_cr( char *text );
G_MODULE_EXPORT char *strip_newlines(char *source);
G_MODULE_EXPORT time_t get_time( int year, int month, int day, int hour, int min, int sec );
+G_MODULE_EXPORT time_t mktime_utc( struct tm *tp );
double gettime( void );
G_MODULE_EXPORT void strip_html( char *msg );
diff --git a/protocols/jabber/jabber_util.c b/protocols/jabber/jabber_util.c
index db5944bc..b8b625f7 100644
--- a/protocols/jabber/jabber_util.c
+++ b/protocols/jabber/jabber_util.c
@@ -666,10 +666,9 @@ int jabber_buddy_remove_bare( struct im_connection *ic, char *bare_jid )
time_t jabber_get_timestamp( struct xt_node *xt )
{
- struct tm tp, utc;
struct xt_node *c;
- time_t res, tres;
char *s = NULL;
+ struct tm tp;
for( c = xt->children; ( c = xt_find_node( c, "x" ) ); c = c->next )
{
@@ -687,30 +686,8 @@ time_t jabber_get_timestamp( struct xt_node *xt )
tp.tm_year -= 1900;
tp.tm_mon --;
- tp.tm_isdst = -1; /* GRRRRRRRRRRR */
-
- res = mktime( &tp );
- /* Problem is, mktime() just gave us the GMT timestamp for the
- given local time... While the given time WAS NOT local. So
- we should fix this now.
-
- Now I could choose between messing with environment variables
- (kludgy) or using timegm() (not portable)... Or doing the
- following, which I actually prefer... */
- gmtime_r( &res, &utc );
- utc.tm_isdst = -1; /* Once more: GRRRRRRRRRRRRRRRRRR!!! */
- if( utc.tm_hour == tp.tm_hour && utc.tm_min == tp.tm_min )
- /* Sweet! We're in UTC right now... */
- return res;
-
- tres = mktime( &utc );
- res += res - tres;
-
- /* Yes, this is a hack. And it will go wrong around DST changes.
- BUT this is more likely to be threadsafe than messing with
- environment variables, and possibly more portable... */
-
- return res;
+
+ return mktime_utc( &tp );
}
struct jabber_error *jabber_error_parse( struct xt_node *node, char *xmlns )