diff options
author | Thomas Roessler <roessler@does-not-exist.org> | 1999-01-06 10:13:01 +0000 |
---|---|---|
committer | Thomas Roessler <roessler@does-not-exist.org> | 1999-01-06 10:13:01 +0000 |
commit | d02b2498d47d9d9e3e6d30cff78e7f5435dee133 (patch) | |
tree | 1f6020ac18919df9dee40b83696e605d5fd83858 /date.c | |
parent | 4a3e38f09949c92947e227122e227ef311a1e170 (diff) |
[unstable] Merge changes from stable: rx -> regex, Byrial's timezone
patch, translation updates.
Diffstat (limited to 'date.c')
-rw-r--r-- | date.c | 46 |
1 files changed, 20 insertions, 26 deletions
@@ -20,50 +20,44 @@ static const char rcsid[]="$Id$"; #include "mutt.h" #include <string.h> -/* returns the seconds west of UTC given `g' and its corresponding gmtime() +/* returns the seconds east of UTC given `g' and its corresponding gmtime() representation */ -static time_t mutt_compute_tz (time_t g, struct tm *utc) +static time_t compute_tz (time_t g, struct tm *utc) { struct tm *lt = localtime (&g); time_t t; + int yday; - t = (((utc->tm_hour - lt->tm_hour) * 60) + (utc->tm_min - lt->tm_min)) * 60; - switch (utc->tm_yday - lt->tm_yday) - { - case 0: - break; - - case 1: - case -364: - case -365: - t += 24 * 60 * 60; - break; + t = (((lt->tm_hour - utc->tm_hour) * 60) + (lt->tm_min - utc->tm_min)) * 60; - case -1: - case 364: - case 365: + if ((yday = (lt->tm_yday - utc->tm_yday))) + { + /* This code is optimized to negative timezones (West of Greenwich) */ + if (yday == -1 || /* UTC passed midnight before localtime */ + yday > 1) /* UTC passed new year before localtime */ t -= 24 * 60 * 60; - break; - - default: - mutt_error _("Please report this program error in the function mutt_mktime."); + else + t += 24 * 60 * 60; } return t; } -time_t mutt_local_tz (void) +/* Returns the local timezone in seconds east of UTC for the time t, + * or for the current time if t is zero. + */ +time_t mutt_local_tz (time_t t) { struct tm *ptm; struct tm utc; - time_t now; - now = time (NULL); - ptm = gmtime (&now); + if (!t) + t = time (NULL); + ptm = gmtime (&t); /* need to make a copy because gmtime/localtime return a pointer to static memory (grr!) */ memcpy (&utc, ptm, sizeof (utc)); - return (mutt_compute_tz (now, &utc)); + return (compute_tz (t, &utc)); } /* converts struct tm to time_t, but does not take the local timezone into @@ -103,7 +97,7 @@ time_t mutt_mktime (struct tm *t, int local) g += t->tm_sec; if (local) - g += mutt_compute_tz (g, t); + g -= compute_tz (g, t); return (g); } |