Example #1
0
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);
}
Example #2
0
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);
}
Example #3
0
/**
 * 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);
}
Example #4
0
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);
}
Example #5
0
/**
 * 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);
}
Example #6
0
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);
}