Top |
Time and Date ConversionsTime and Date Conversions — Converting from timestamps to date structures and back |
void | glk_time_to_date_utc () |
void | glk_time_to_date_local () |
void | glk_simple_time_to_date_utc () |
void | glk_simple_time_to_date_local () |
void | glk_date_to_time_utc () |
void | glk_date_to_time_local () |
glsi32 | glk_date_to_simple_time_utc () |
glsi32 | glk_date_to_simple_time_local () |
This section describes functions for converting timestamps to more human-readable date structures and back.
void glk_time_to_date_utc (glktimeval_t *time
,glkdate_t *date
);
Convert the given timestamp (as returned by glk_current_time()
) to a
broken-out structure. This function returns a date and time in universal time
(GMT).
The seconds value may be 60 because of a leap second.
time |
A glktimeval_t structure as returned by |
|
date |
An empty glkdate_t structure to fill in. |
void glk_time_to_date_local (glktimeval_t *time
,glkdate_t *date
);
Does the same thing as glk_time_to_date_utc()
, but this function returns
local time.
time |
A glktimeval_t structure as returned by |
|
date |
An empty glkdate_t structure to fill in. |
void glk_simple_time_to_date_utc (glsi32 time
,glui32 factor
,glkdate_t *date
);
Convert the given timestamp (as returned by glk_current_simple_time()
) to a
broken-out structure in universal time. The time
argument is multiplied by
factor
to produce a Unix timestamp.
Since the resolution of glk_simple_time_to_date_utc()
and
glk_simple_time_to_date_local()
is no better than seconds, they will return
zero for the microseconds value.
time |
Timestamp as returned by |
|
factor |
Factor by which to multiply |
|
date |
An empty glkdate_t structure to fill in. |
void glk_simple_time_to_date_local (glsi32 time
,glui32 factor
,glkdate_t *date
);
Does the same thing as glk_simple_time_to_date_utc()
, but fills in the date
structure in local time.
time |
Timestamp as returned by |
|
factor |
Factor by which to multiply |
|
date |
An empty glkdate_t structure to fill in. |
void glk_date_to_time_utc (glkdate_t *date
,glktimeval_t *time
);
Convert the broken-out structure (interpreted as universal time) to a
timestamp. 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 for the seconds value. (I.e., the high_sec
and low_sec
fields
both $FFFFFFFF. The microseconds field is undefined in this case.)
date |
A date in the form of a glkdate_t structure. |
|
time |
An empty glktimeval_t structure to fill in. |
void glk_date_to_time_local (glkdate_t *date
,glktimeval_t *time
);
Does the same thing as glk_date_to_time_utc()
, but interprets the broken-out
structure as local time.
The glk_date_to_time_local()
function may not be smart about Daylight Saving
Time conversions.
If implemented with the mktime()
libc function, it should use the negative
tm_isdst
flag to “attempt to divine whether summer time is in effect”.
date |
A date in the form of a glkdate_t structure. |
|
time |
An empty glktimeval_t structure to fill in. |
glsi32 glk_date_to_simple_time_utc (glkdate_t *date
,glui32 factor
);
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.
date |
A date in the form of a glkdate_t structure. |
|
factor |
Factor by which to divide the time value. |
glsi32 glk_date_to_simple_time_local (glkdate_t *date
,glui32 factor
);
Does the same thing as glk_date_to_simple_time_utc()
, but interprets the
broken-out structure as local time.
date |
A date in the form of a glkdate_t structure. |
|
factor |
Factor by which to divide the time value. |
typedef struct { glsi32 year; /* full (four-digit) year */ glsi32 month; /* 1-12, 1 is January */ glsi32 day; /* 1-31 */ glsi32 weekday; /* 0-6, 0 is Sunday */ glsi32 hour; /* 0-23 */ glsi32 minute; /* 0-59 */ glsi32 second; /* 0-59, maybe 60 during a leap second */ glsi32 microsec; /* 0-999999 */ } glkdate_t;
This structure represents a human-readable date in a specific timezone.
glsi32 |
The full (four-digit) year |
|
glsi32 |
The month number, ranging from 1-12, 1 is January |
|
glsi32 |
The day of the month, ranging from 1-31 |
|
glsi32 |
The day of the week, ranging from 0-6, 0 is Sunday |
|
glsi32 |
The hour of the day, ranging from 0-23 |
|
glsi32 |
The minute of the hour, ranging from 0-59 |
|
glsi32 |
The second of the minute, ranging from 0-59; may be 60 during a leap second |
|
glsi32 |
The fraction of the second in microseconds, ranging from 0-999999 |