Browse code

- _timegm resets the information about DST in struct tm structure because the date and time in that structure is in UTC. - added conversion functions that can convert time_t values between local timezones and utc.

Jan Janak authored on 21/06/2007 11:38:42
Showing 2 changed files
... ...
@@ -101,7 +101,8 @@ time_t _timegm(struct tm* t)
101 101
 {
102 102
 	time_t tl, tb;
103 103
 	struct tm* tg;
104
-	
104
+
105
+	t->tm_isdst = 0;
105 106
 	tl = mktime(t);
106 107
 	if (tl == -1) {
107 108
 		t->tm_hour--;
... ...
@@ -127,6 +128,29 @@ time_t _timegm(struct tm* t)
127 127
 }
128 128
 
129 129
 
130
+/* Convert time_t value that is relative to local timezone to UTC */
131
+time_t local2utc(time_t in)
132
+{
133
+	struct tm* tt;
134
+	tt = gmtime(&in);
135
+	tt->tm_isdst = -1;
136
+	return mktime(tt);
137
+}
138
+
139
+
140
+/* Convert time_t value in UTC to to value relative to local time zone */
141
+time_t utc2local(time_t in)
142
+{
143
+	struct tm* tt;
144
+	tt = localtime(&in);
145
+#ifdef HAVE_TIMEGM
146
+	return timegm(tt);
147
+#else
148
+	return _timegm(tt);
149
+#endif
150
+}
151
+
152
+
130 153
 /*
131 154
  * Return str as zero terminated string allocated
132 155
  * using pkg_malloc
... ...
@@ -526,6 +526,11 @@ int group2gid(int* gid, char* group);
526 526
  */
527 527
 time_t _timegm(struct tm* t);
528 528
 
529
+/* Convert time_t value that is relative to local timezone to UTC */
530
+time_t local2utc(time_t in);
531
+
532
+/* Convert time_t value in UTC to to value relative to local time zone */
533
+time_t utc2local(time_t in);
529 534
 
530 535
 /*
531 536
  * Return str as zero terminated string allocated