#1207: Add helper to get Unix time in GMT
On Windows, time() is returning a value which if offset by the selected time-zone. Provide a variant which is always in GMT.
This commit is contained in:
parent
aea71cf0af
commit
df57a23512
@ -1134,3 +1134,15 @@ char *tzstring (const char* string)
|
||||
|
||||
return strncpy (p, string, needed);
|
||||
}
|
||||
|
||||
time_t sgGMTime()
|
||||
{
|
||||
struct tm now;
|
||||
time_t now_sec = time(0);
|
||||
#if defined(SG_WINDOWS)
|
||||
now = *gmtime(&now_sec);
|
||||
#else
|
||||
gmtime_r(&now_sec, &now);
|
||||
#endif
|
||||
return mktime(&now);
|
||||
}
|
@ -41,6 +41,11 @@ void show (const char *zone, time_t t, int v);
|
||||
/* adapted from <time.h> */
|
||||
struct tm * fgLocaltime (const time_t *t, const char *tzName);
|
||||
|
||||
/* version of time() which returns a value in GMT/UTC, without
|
||||
any timezone adjustment. Necessary on Windows where calling time()
|
||||
returns a value in the local time-zone. */
|
||||
time_t sgGMTime();
|
||||
|
||||
/* Prototype for the internal function to get information based on TZ. */
|
||||
extern struct tm *fgtz_convert (const time_t *t, int use_localtime,
|
||||
struct tm *tp, const char *tzName);
|
||||
|
Loading…
Reference in New Issue
Block a user