src/protocols/jabber/jutil.c

changeset 8577
64f25a17f8e4
parent 8401
9fe6cadf2581
child 9954
52a14a58a33e
equal deleted inserted replaced
8576:2bbdbfa1bb83 8577:64f25a17f8e4
23 #include "util.h" 23 #include "util.h"
24 24
25 #include "chat.h" 25 #include "chat.h"
26 #include "presence.h" 26 #include "presence.h"
27 #include "jutil.h" 27 #include "jutil.h"
28
29 time_t str_to_time(const char *timestamp)
30 {
31 struct tm t;
32 time_t retval = 0;
33 char buf[32];
34 char *c;
35 int tzoff = 0;
36
37 time(&retval);
38 localtime_r(&retval, &t);
39
40 snprintf(buf, sizeof(buf), "%s", timestamp);
41 c = buf;
42
43 /* 4 digit year */
44 if(!sscanf(c, "%04d", &t.tm_year)) return 0;
45 c+=4;
46 if(*c == '-')
47 c++;
48
49 t.tm_year -= 1900;
50
51 /* 2 digit month */
52 if(!sscanf(c, "%02d", &t.tm_mon)) return 0;
53 c+=2;
54 if(*c == '-')
55 c++;
56
57 t.tm_mon -= 1;
58
59 /* 2 digit day */
60 if(!sscanf(c, "%02d", &t.tm_mday)) return 0;
61 c+=2;
62 if(*c == 'T') { /* we have more than a date, keep going */
63 c++; /* skip the "T" */
64
65 /* 2 digit hour */
66 if(sscanf(c, "%02d:%02d:%02d", &t.tm_hour, &t.tm_min, &t.tm_sec)) {
67 int tzhrs, tzmins;
68 c+=8;
69 if(*c == '.') /* dealing with precision we don't care about */
70 c += 4;
71
72 if((*c == '+' || *c == '-') &&
73 sscanf(c+1, "%02d:%02d", &tzhrs, &tzmins)) {
74 tzoff = tzhrs*60*60 + tzmins*60;
75 if(*c == '+')
76 tzoff *= -1;
77 }
78
79 #ifdef HAVE_TM_GMTOFF
80 tzoff += t.tm_gmtoff;
81 #else
82 # ifdef HAVE_TIMEZONE
83 tzset(); /* making sure */
84 tzoff -= timezone;
85 # endif
86 #endif
87 }
88 }
89 retval = mktime(&t);
90
91 retval += tzoff;
92
93 return retval;
94 }
95 28
96 const char *jabber_get_state_string(int s) { 29 const char *jabber_get_state_string(int s) {
97 switch(s) { 30 switch(s) {
98 case JABBER_STATE_AWAY: 31 case JABBER_STATE_AWAY:
99 return _("Away"); 32 return _("Away");

mercurial