* mu-date: small optimization
This commit is contained in:
@ -222,10 +222,10 @@ mu_date_interpret (const char *datespec, gboolean is_begin)
|
|||||||
time_t
|
time_t
|
||||||
mu_date_str_to_time_t (const char* date, gboolean local)
|
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) {
|
||||||
setenv ("TZ", "", 1);
|
strcpy (oldtz, tz);
|
||||||
tzset ();
|
setenv ("TZ", "", 1);
|
||||||
} else
|
tzset ();
|
||||||
tz = NULL;
|
} else
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user