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