GATE
Loading...
Searching...
No Matches
times.h File Reference

Date and time management and conversion functions. More...

#include "gate/gate_core_api.h"
#include "gate/gatetypes.h"

Functions

GATE_CORE_API gate_result_t gate_date_to_time (gate_datetime_t const *source, gate_time_t *dest)
 Converts a gregorian date and daytime into a time value.
 
GATE_CORE_API gate_result_t gate_date_to_string (gate_datetime_t const *date, gate_int16_t bias, char const *format, char *dest, gate_size_t *destsize)
 Prints a date structure into a string using the specified format.
 
GATE_CORE_API gate_size_t gate_date_parse_string (char const *source, gate_size_t sourcelen, gate_datetime_t *dest, gate_int16_t *bias)
 Parses a ISO 8601 time string and fills a datetime record with contents.
 
GATE_CORE_API gate_size_t gate_date_parse_month (char const *source, gate_size_t sourcelen, gate_uint8_t *mon)
 Parses a calendar month name into a month number.
 
GATE_CORE_API gate_day_id_t gate_date_to_day_id (gate_date_t const *date)
 Converts a gregorian date to a unique day-id (counted days since 1601-01-01)
 
GATE_CORE_API gate_result_t gate_date_from_day_id (gate_day_id_t day_id, gate_date_t *date)
 Converts a day-id into a gregorian date structure.
 
GATE_CORE_API gate_uint8_t gate_date_day_of_week (gate_day_id_t day_id)
 Returns the week-day id of the given day-id.
 
GATE_CORE_API gate_uint16_t gate_date_day_of_year (gate_date_t const *date)
 Returns day count of day within year of the given gregorian date.
 
GATE_CORE_API gate_uint8_t gate_date_week_of_year (gate_date_t const *date, gate_bool_t monday_starts_week)
 Returns the week-count within year of the given gregorian date.
 
GATE_CORE_API gate_result_t gate_time_now (gate_time_t *now)
 Returns the current time from the system's clock.
 
GATE_CORE_API gate_result_t gate_time_to_datetime (gate_time_t const *source, gate_datetime_t *dest)
 Converts a time structure into a gregorian date-time structure.
 
GATE_CORE_API gate_result_t gate_time_to_string (gate_time_t const *source, char const *format, char *dest, gate_size_t *destsize)
 Prints time structure as a formated string.
 
GATE_CORE_API gate_result_t gate_time_parse_string (char const *source, gate_size_t sourcelen, gate_time_t *dest)
 Parses ISO8601 formated time string into a time-structure.
 
GATE_CORE_API gate_result_t gate_time_from_unix (gate_int64_t sourceunixseconds, gate_timestamp_t *dest)
 Converts UNIX-timestamp into GATE timestamp.
 
GATE_CORE_API gate_result_t gate_time_from_timestamp (gate_timestamp_t source, gate_time_t *dest)
 Converts timestamp into time-structure.
 
GATE_CORE_API gate_result_t gate_time_to_unix (gate_timestamp_t sourcetime, gate_int64_t *destunixseconds)
 Converts GATE timestamp into UNIX timestamp.
 
GATE_CORE_API gate_day_id_t gate_time_to_day_id (gate_timestamp_t timestamp)
 Converts GATE timestamp into day-id.
 
GATE_CORE_API gate_result_t gate_time_from_day_id (gate_day_id_t day_id, gate_timestamp_t *dest)
 Creates a GATE timestamp from a day-id.
 
GATE_CORE_API gate_result_t gate_timecounter_now (gate_timecounter_t *now)
 Creates a monotonic timestamp from the system's clock.
 
GATE_CORE_API gate_int64_t gate_timecounter_diff (gate_timecounter_t tc1, gate_timecounter_t tc2)
 Returns the difference of two timecounter value (returnvalue = tc1 - tc2)
 
GATE_CORE_API gate_timecounter_t gate_timecounter_add (gate_timecounter_t tc, gate_int64_t microseconds)
 Creates a new timecounter value by adding microseconds to a given timecounter.
 

Detailed Description

Date and time management and conversion functions.

Function Documentation

◆ gate_date_to_time()

GATE_CORE_API gate_result_t gate_date_to_time ( gate_datetime_t const * source,
gate_time_t * dest )

Converts a gregorian date and daytime into a time value.

Parameters
[in]sourcepointer to input datetime structure
[out]destpointer to output time structure
Returns
value GATE_RESULT_* code

◆ gate_date_to_string()

GATE_CORE_API gate_result_t gate_date_to_string ( gate_datetime_t const * date,
gate_int16_t bias,
char const * format,
char * dest,
gate_size_t * destsize )

Prints a date structure into a string using the specified format.

Parameters
[in]datepointer to input datetime structure
[in]biasbias in minutes of the given datetime structure compared to UTC
[in]formatformat string for time representation (NULL == ISO 8601, which is "{YYYY}-{MM}-{DD}T{hh}:{mm}:{ss}.{SSS}{bias}")
[out]destpointer to output string buffer
[in,out]destsizepointer to size of string buffer, retrieving the consumed bytes afterwards
Returns
value GATE_RESULT_* code

◆ gate_date_parse_string()

GATE_CORE_API gate_size_t gate_date_parse_string ( char const * source,
gate_size_t sourcelen,
gate_datetime_t * dest,
gate_int16_t * bias )

Parses a ISO 8601 time string and fills a datetime record with contents.

Parameters
[in]sourcepointer to source string to be parsed
[in]sourcelenlength of source string in bytes
[out]destpointer to output date-time structure
[out]biaspointer to output bias in minutes from UTC
Returns
parsed characters from source string, 0 == error

◆ gate_date_parse_month()

GATE_CORE_API gate_size_t gate_date_parse_month ( char const * source,
gate_size_t sourcelen,
gate_uint8_t * mon )

Parses a calendar month name into a month number.

Parameters
[in]sourcepointer to source string to be parsed
[in]sourcelenlength of source string in bytes
[out]monpointer to output month number
Returns
parsed characters from source string, 0 == error

◆ gate_date_to_day_id()

GATE_CORE_API gate_day_id_t gate_date_to_day_id ( gate_date_t const * date)

Converts a gregorian date to a unique day-id (counted days since 1601-01-01)

Parameters
[in]datepointer to date structure to be converted
Returns
day-id of date

◆ gate_date_from_day_id()

GATE_CORE_API gate_result_t gate_date_from_day_id ( gate_day_id_t day_id,
gate_date_t * date )

Converts a day-id into a gregorian date structure.

Parameters
[in]day_idpointer to source string to be parsed
[out]datepointer to output date-time structure
Returns
value GATE_RESULT_* code

◆ gate_date_day_of_week()

GATE_CORE_API gate_uint8_t gate_date_day_of_week ( gate_day_id_t day_id)

Returns the week-day id of the given day-id.

Parameters
[in]day_idid of day to be used
Returns
day of week GATE_DAY_* (0=Sun, 1=Mon, 2=Tue, ..., 6=Sat)

◆ gate_date_day_of_year()

GATE_CORE_API gate_uint16_t gate_date_day_of_year ( gate_date_t const * date)

Returns day count of day within year of the given gregorian date.

Parameters
[in]datepointer to date to be analyzed
Returns
returns day-counter (1 = 1st of Jan, 32 = 1st of Feb, ...)

◆ gate_date_week_of_year()

GATE_CORE_API gate_uint8_t gate_date_week_of_year ( gate_date_t const * date,
gate_bool_t monday_starts_week )

Returns the week-count within year of the given gregorian date.

Parameters
[in]datepointer to date to be analyzed
[in]monday_starts_weektrue=starts with monday, false=starts with sunday
Returns
count of week (1 = first week, 2 = second week, ...)

◆ gate_time_now()

GATE_CORE_API gate_result_t gate_time_now ( gate_time_t * now)

Returns the current time from the system's clock.

Parameters
[out]nowPointer to time structure retrieving the current time
Returns
value GATE_RESULT_* code

◆ gate_time_to_datetime()

GATE_CORE_API gate_result_t gate_time_to_datetime ( gate_time_t const * source,
gate_datetime_t * dest )

Converts a time structure into a gregorian date-time structure.

Parameters
[in]sourcepointer to input time structure
[out]destpointer to output date-time structure
Returns
value GATE_RESULT_* code

◆ gate_time_to_string()

GATE_CORE_API gate_result_t gate_time_to_string ( gate_time_t const * source,
char const * format,
char * dest,
gate_size_t * destsize )

Prints time structure as a formated string.

Parameters
[in]sourcepointer to input time structure
[in]formatformat output string (NULL == ISO8601)
[out]destpointer to output string buffer
[in,out]destsizepointer to output string capacity, receives used bytes afterwards
Returns
value GATE_RESULT_* code

◆ gate_time_parse_string()

GATE_CORE_API gate_result_t gate_time_parse_string ( char const * source,
gate_size_t sourcelen,
gate_time_t * dest )

Parses ISO8601 formated time string into a time-structure.

Parameters
[in]sourcepointer to input string
[in]sourcelenlength of source string in bytes
[out]destpointer to output time structure
Returns
value GATE_RESULT_* code

◆ gate_time_from_unix()

GATE_CORE_API gate_result_t gate_time_from_unix ( gate_int64_t sourceunixseconds,
gate_timestamp_t * dest )

Converts UNIX-timestamp into GATE timestamp.

Parameters
[in]sourceunixsecondsUnix time in seconds since 1970-01-01 00:00
[out]destpointer to output time structure
Returns
value GATE_RESULT_* code

◆ gate_time_from_timestamp()

GATE_CORE_API gate_result_t gate_time_from_timestamp ( gate_timestamp_t source,
gate_time_t * dest )

Converts timestamp into time-structure.

Parameters
[in]sourcetimestamp value to be converted
[out]destPointer to output time-structure
Returns
value GATE_RESULT_* code

◆ gate_time_to_unix()

GATE_CORE_API gate_result_t gate_time_to_unix ( gate_timestamp_t sourcetime,
gate_int64_t * destunixseconds )

Converts GATE timestamp into UNIX timestamp.

Parameters
[in]sourcetimeGATE timestamp (Microseconds since 1601-01-01)
[out]destunixsecondspointer to output UNIX timestamp
Returns
value GATE_RESULT_* code

◆ gate_time_to_day_id()

GATE_CORE_API gate_day_id_t gate_time_to_day_id ( gate_timestamp_t timestamp)

Converts GATE timestamp into day-id.

Parameters
[in]timestampGATE timestamp (Microseconds since 1601-01-01)
Returns
days since 1601-01-01

◆ gate_time_from_day_id()

GATE_CORE_API gate_result_t gate_time_from_day_id ( gate_day_id_t day_id,
gate_timestamp_t * dest )

Creates a GATE timestamp from a day-id.

Parameters
[in]day_iddays since 1601-01-01
[out]destpointer to output GATE timestamp
Returns
value GATE_RESULT_* code

◆ gate_timecounter_now()

GATE_CORE_API gate_result_t gate_timecounter_now ( gate_timecounter_t * now)

Creates a monotonic timestamp from the system's clock.

Parameters
[out]nowpointer to output timecounter value
Returns
value GATE_RESULT_* code

◆ gate_timecounter_diff()

GATE_CORE_API gate_int64_t gate_timecounter_diff ( gate_timecounter_t tc1,
gate_timecounter_t tc2 )

Returns the difference of two timecounter value (returnvalue = tc1 - tc2)

Parameters
[in]tc1first timecounter value
[in]tc2second timecounter value
Returns
difference in microseconds between t1 and t2

◆ gate_timecounter_add()

GATE_CORE_API gate_timecounter_t gate_timecounter_add ( gate_timecounter_t tc,
gate_int64_t microseconds )

Creates a new timecounter value by adding microseconds to a given timecounter.

Parameters
[in]tcdays since 1601-01-01
[out]microsecondsamount of microseconds to be added to timecounter value
Returns
new timecounter value (returnvalue = tc + microseconds)