void glk_current_time(glktimeval_t *time) { struct timeval tv; if (gettimeofday(&tv, NULL)) { gli_timestamp_to_time(0, 0, time); gli_strict_warning("current_time: gettimeofday() failed."); return; } gli_timestamp_to_time(tv.tv_sec, tv.tv_usec, time); }
/** * glk_current_time: * @time: pointer to a #glktimeval_t structure. * * The current Unix time is stored in the structure @time. (The argument may not * be %NULL.) This is the number of seconds since the beginning of 1970 (UTC). * * The first two values in the structure should be considered a single * <emphasis>signed</emphasis> 64-bit number. This allows the #glktimeval_t to * store a reasonable range of values in the future and past. The @high_sec * value will remain zero until sometime in 2106. If your computer is running in * 1969, perhaps due to an unexpected solar flare, then @high_sec will be * negative. * * The third value in the structure represents a fraction of a second, in * microseconds (from 0 to 999999). The resolution of the glk_current_time() * call is platform-dependent; the @microsec value may not be updated * continuously. */ void glk_current_time(glktimeval_t *time) { g_return_if_fail(time != NULL); GTimeVal tv; g_get_current_time(&tv); gli_timestamp_to_time(tv.tv_sec, tv.tv_usec, time); }
void glk_date_to_time_local(glkdate_t *date, glktimeval_t *time) { time_t timestamp; struct tm tm; glsi32 microsec; microsec = gli_date_to_tm(date, &tm); tm.tm_isdst = -1; timestamp = mktime(&tm); gli_timestamp_to_time(timestamp, microsec, time); }
void glk_date_to_time_utc(glkdate_t *date, glktimeval_t *time) { time_t timestamp; struct tm tm; glsi32 microsec; microsec = gli_date_to_tm(date, &tm); /* The timegm function is not standard POSIX. If it's not available on your platform, try setting the env var "TZ" to "", calling mktime(), and then resetting "TZ". */ timestamp = timegm(&tm); gli_timestamp_to_time(timestamp, microsec, time); }