The System Clock

The System Clock — Getting the current time from the system clock

Functions

Types and Values

Includes

#include <libchimara/glk.h>

Description

You can get the current time, either as a Unix timestamp (seconds since 1970) or as a broken-out structure of time elements (year, month, day, hour, minute, second).

The system clock is not guaranteed to line up with timer events (see Timer Events). Timer events may be delivered late according to the system clock.

Functions

glk_current_time ()

void
glk_current_time (glktimeval_t *time);

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 signed 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.

Parameters

time

pointer to a glktimeval_t structure.

 

glk_current_simple_time ()

glsi32
glk_current_simple_time (glui32 factor);

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.

Parameters

factor

Factor by which to divide the time value.

 

Returns

Unix time divided by factor , truncated to 32 bits.

Types and Values

glktimeval_t

typedef struct {
    glsi32 high_sec;
    glui32 low_sec;
    glsi32 microsec;
} glktimeval_t;

This structure represents the Unix timestamp, i.e. the number of seconds since January 1, 1970.

Members

glsi32 high_sec;

The most significant 32 bits of the timestamp in seconds.

 

glui32 low_sec;

The least significant 32 bits of the timestamp in seconds.

 

glsi32 microsec;

The fraction of the timestamp, in microseconds, ranging from 0-999999.