Commit 42c4f5fa 42c4f5fa1e04932b02911ca27ff0096a6e808235 by Sergey Poznyakoff

Fixed error introduced in the initial implementation of

mu_mktime (now mu_tm2time). The comment on mu_tm2time() describes it.
Revert the sign of the return value of mu_utc_offset(), so it
agrees with the accepted timezone rules (+ for eastern
hemisphere, - for western).
1 parent 2106dcd2
...@@ -31,23 +31,30 @@ ...@@ -31,23 +31,30 @@
31 31
32 mktime() always treats tm as if it was localtime, so convert it 32 mktime() always treats tm as if it was localtime, so convert it
33 to UTC, then adjust by the tm's real timezone, if it is known. 33 to UTC, then adjust by the tm's real timezone, if it is known.
34
35 NOTE: 1. mktime converts localtime struct tm to *time_t in UTC*
36 2. adding mu_utc_offset() compensates for the localtime
37 corrections in in mktime(), i.e. it yields the time_t in
38 the current zone of struct tm.
39 3. finally, subtracting TZ offset yields the UTC.
34 */ 40 */
35 time_t 41 time_t
36 mu_tm2time (struct tm *timeptr, mu_timezone* tz) 42 mu_tm2time (struct tm *timeptr, mu_timezone* tz)
37 { 43 {
38 int offset = tz ? tz->utc_offset : 0; 44 int offset = tz ? tz->utc_offset : 0;
39 45
40 return mktime(timeptr) - mu_utc_offset() + offset; 46 return mktime(timeptr) + mu_utc_offset() - offset;
41 } 47 }
42 48
43 /* Convert time 0 at UTC to our localtime, that tells us the offset 49 /* Convert time 0 at UTC to our localtime, that tells us the offset
44 of our current timezone from UTC. */ 50 of our current timezone from UTC. */
45 time_t mu_utc_offset(void) 51 time_t
52 mu_utc_offset(void)
46 { 53 {
47 time_t t = 0; 54 time_t t = 0;
48 struct tm* tm = gmtime(&t); 55 struct tm* tm = gmtime(&t);
49 56
50 return mktime(tm); 57 return - mktime(tm);
51 } 58 }
52 59
53 static const char *months[] = 60 static const char *months[] =
......