* mu-date: small optimization

This commit is contained in:
djcb
2013-09-07 12:57:53 +03:00
parent 13bad9a889
commit 827dfbecdb

View File

@ -225,7 +225,7 @@ mu_date_str_to_time_t (const char* date, gboolean local)
struct tm tm;
char mydate[14 + 1]; /* YYYYMMDDHHMMSS */
time_t t;
char *tz;
char oldtz[16];
memset (&tm, 0, sizeof(struct tm));
strncpy (mydate, date, 15);
@ -242,25 +242,26 @@ mu_date_str_to_time_t (const char* date, gboolean local)
tm.tm_isdst = -1; /* let mktime figure out the dst */
if (!local) { /* temporarily switch to UTC */
const char *tz;
tz = getenv ("TZ");
tz = tz ? g_strdup (tz) : NULL;
if (tz && strlen (tz) < sizeof(tz) -1) {
strcpy (oldtz, tz);
setenv ("TZ", "", 1);
tzset ();
} else
tz = NULL;
local = TRUE; /* already */
}
t = mktime (&tm);
if (!local) { /* switch back */
if (tz)
setenv("TZ", tz, 1);
if (oldtz)
setenv("TZ", oldtz, 1);
else
unsetenv("TZ");
tzset ();
}
g_free (tz);
return t;
}