/** * glk_current_simple_time: * @factor: Factor by which to divide the time value. * * If dealing with 64-bit values is awkward, you can also get the current time * as a lower-resolution 32-bit value. This is simply the Unix time divided by * the @factor argument (which must not be zero). For example, if factor is 60, * the result will be the number of minutes since 1970 (rounded towards negative * infinity). If factor is 1, you will get the Unix time directly, but the value * will be truncated starting some time in 2038. * * Returns: Unix time divided by @factor, truncated to 32 bits. */ glsi32 glk_current_simple_time(glui32 factor) { g_return_val_if_fail(factor != 0, 0); GTimeVal tv; g_get_current_time(&tv); return gli_simplify_time(tv.tv_sec, factor); }
/** * glk_date_to_simple_time_local: * @date: A date in the form of a #glkdate_t structure. * @factor: Factor by which to divide the time value. * * Does the same thing as glk_date_to_simple_time_utc(), but interprets the * broken-out structure as local time. * * Returns: a timestamp divided by @factor, and truncated to 32 bits, or -1 on * error. */ glsi32 glk_date_to_simple_time_local(glkdate_t *date, glui32 factor) { g_return_val_if_fail(date != NULL, 0); g_return_val_if_fail(factor != 0, 0); time_t timestamp; struct tm tm; gli_date_to_tm(date, &tm); tm.tm_isdst = -1; timestamp = mktime(&tm); return gli_simplify_time(timestamp, factor); }
glsi32 glk_date_to_simple_time_local(glkdate_t *date, glui32 factor) { time_t timestamp; struct tm tm; if (factor == 0) { gli_strict_warning("date_to_simple_time_local: factor cannot be zero."); return 0; } gli_date_to_tm(date, &tm); tm.tm_isdst = -1; timestamp = mktime(&tm); return gli_simplify_time(timestamp, factor); }
glsi32 glk_current_simple_time(glui32 factor) { struct timeval tv; if (factor == 0) { gli_strict_warning("current_simple_time: factor cannot be zero."); return 0; } if (gettimeofday(&tv, NULL)) { gli_strict_warning("current_simple_time: gettimeofday() failed."); return 0; } return gli_simplify_time(tv.tv_sec, factor); }
/** * glk_date_to_simple_time_utc: * @date: A date in the form of a #glkdate_t structure. * @factor: Factor by which to divide the time value. * * Convert the broken-out structure (interpreted as universal time) to a * timestamp divided by @factor. The weekday value in @date is ignored. The * other values need not be in their normal ranges; they will be normalized. * * If the time cannot be represented by the platform's time library, this may * return -1. * * Returns: a timestamp divided by @factor, and truncated to 32 bits, or -1 on * error. */ glsi32 glk_date_to_simple_time_utc(glkdate_t *date, glui32 factor) { g_return_val_if_fail(date != NULL, 0); g_return_val_if_fail(factor != 0, 0); time_t timestamp; struct tm tm; 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". */ tm.tm_isdst = 0; timestamp = timegm(&tm); return gli_simplify_time(timestamp, factor); }
glsi32 glk_date_to_simple_time_utc(glkdate_t *date, glui32 factor) { time_t timestamp; struct tm tm; if (factor == 0) { gli_strict_warning("date_to_simple_time_utc: factor cannot be zero."); return 0; } 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); return gli_simplify_time(timestamp, factor); }