Timex¶
Timestamp representation, computation, and conversion.
-
const int8_t
TM_MON_DAYS()¶ The number of days in common years.
See also
-
const int16_t
TM_MON_DAYS_ACCU()¶ The prefixsum of the number of days in common years.
See also
-
timex_t
timex_add(const timex_t a, const timex_t b)¶ Adds two timestamps.
Parameters
a: First summand b: Second summand Return values
- The sum of the two timestamps
-
timex_t
timex_sub(const timex_t a, const timex_t b)¶ Subtracts two timestamps.
Parameters
a: The minuend b: The subtrahend Return values
- The difference a - b
-
timex_t
timex_set(uint32_t seconds, uint32_t microseconds)¶ Initializes a timex timestamp.
Parameters
seconds: Number of seconds to set microseconds: Number of microseconds to set Return values
- The initialized timex timestamp
-
int
timex_cmp(const timex_t a, const timex_t b)¶ Compares two timex timestamps.
Parameters
a: The first timestamp to compare to b: The second timestamp to compare with Return values
- -1 when a is smaller
- 0 if equal
- 1 if a is bigger
-
void
timex_normalize(timex_t * time)¶ Corrects timex structure so that microseconds < 1000000.
Parameters
time: Pointer to the timestamp to normalize
-
int
timex_isnormalized(const timex_t * time)¶ Tests a timex timestamp for normalization.
Parameters
time: Pointer to the timestamp to check Return values
- true for a normalized timex_t
- false otherwise
-
uint64_t
timex_uint64(const timex_t a)¶ Converts a timex timestamp to a 64 bit value.
Parameters
a: The timestamp to convert Return values
- timex representation as uint64_t
-
timex_t
timex_from_uint64(const uint64_t timestamp)¶ Converts a 64 bit value of microseconds to a timex timestamp.
Parameters
timestamp: The timestamp to convert. Return values
- a timex representation of an uint64 timestamp.
-
const char *
timex_to_str(timex_t t, char * timestamp)¶ Converts a timex timestamp to a string.
Parameters
t: The timestamp to convert timestamp: The output char buffer for the converted timestamp Note
The timestamp will be normalized
Return values
- A pointer to the string representation of the timestamp
-
int
tm_is_leap_year(unsigned year)¶ Tells if a given year is a leap year in the Gregorian calendar.
Parameters
year: The year. Probably should be ≥ 1582, but needs to be ≥ 1. Return values
1if it is a leap year,0if it is a common year.
-
int
tm_doomsday(int year)¶ Returns the congruent weekday of the Doomsday (March 0).
Only applies for years in the Gregorian calendar.
Parameters
year: The year. Probably should be ≥ 1582, but needs to be ≥ 1. Return values
- The result
% 7is the weekday of the Doomsday of the given year.
- The result
-
void
tm_get_wyday(int year, int mon, int mday, int * wday, int * yday)¶ Calculates the day of the year and the weekday of a given date.
Illegal dates are not catched.
Parameters
year: The year. Probably should be ≥ 1582, but needs to be ≥ 1. mon: The month, TM_MON_JAN to TM_MON_DEC. mday: The day in the month, 1 to 31. wday: Returns the day of the week. yday: Returns the day of the year (Jan 1st is 0).
-
void
tm_fill_derived_values(struct tm * tm)¶ Fills in
struct tm::tm_wdayandstruct tm::tm_ydaygiven a date.struct tm::tm_year,struct tm::tm_mon, andstruct tm::tm_mdayneed to be set before you call this function.Parameters
tm: The datum to operate on.
-
int
tm_is_valid_date(int year, int mon, int mday)¶ Tests if a date is valid.
Dates before 1582-10-15 are invalid.
Parameters
year: The year. mon: The month. mday: The day in the month. Return values
- 0 iff the date is invalid.
-
int
tm_is_valid_time(int hour, int min, int sec)¶ Shallow test if a time is valid.
This function accepts leap seconds at any given time, because the timezone is unknown.
Parameters
hour: The hour. min: The minutes. sec: The seconds. Return values
- 0 iff the time is invalid.
-
US_PER_SEC¶ The number of microseconds per second.
1
(1000000U)
-
SEC_PER_MIN¶ The number of seconds per minute.
1
(60U)
-
CS_PER_SEC¶ The number of centiseconds per second.
1
(100U)
-
MS_PER_SEC¶ The number of milliseconds per second.
1
(1000U)
-
US_PER_MS¶ The number of microseconds per millisecond.
1
(1000U)
-
NS_PER_US¶ The number of nanoseconds per microsecond.
1
(1000U)
-
TIMEX_MAX_STR_LEN¶ The maximum length of the string representation of a timex timestamp.
1
(20)
-
TM_WDAY_SUN¶ Sunday in
struct tm::tm_wday.1
(0)
-
TM_WDAY_MON¶ Monday in
struct tm::tm_wday.1
(1)
-
TM_WDAY_TUE¶ Tuesday in
struct tm::tm_wday.1
(2)
-
TM_WDAY_WED¶ Wednesday in
struct tm::tm_wday.1
(3)
-
TM_WDAY_THU¶ Thursday in
struct tm::tm_wday.1
(4)
-
TM_WDAY_FRI¶ Friday in
struct tm::tm_wday.1
(5)
-
TM_WDAY_SAT¶ Saturday in
struct tm::tm_wday.1
(6)
-
TM_MON_JAN¶ January in
struct tm::tm_mon1
( 0)
-
TM_MON_FEB¶ February in
struct tm::tm_mon1
( 1)
-
TM_MON_MAR¶ March in
struct tm::tm_mon1
( 2)
-
TM_MON_APR¶ April in
struct tm::tm_mon1
( 3)
-
TM_MON_MAY¶ May in
struct tm::tm_mon1
( 4)
-
TM_MON_JUN¶ June in
struct tm::tm_mon1
( 5)
-
TM_MON_JUL¶ July in
struct tm::tm_mon1
( 6)
-
TM_MON_AUG¶ August in
struct tm::tm_mon1
( 7)
-
TM_MON_SEP¶ September in
struct tm::tm_mon1
( 8)
-
TM_MON_OCT¶ October in
struct tm::tm_mon1
( 9)
-
TM_MON_NOV¶ November in
struct tm::tm_mon1
(10)
-
TM_MON_DEC¶ December in
struct tm::tm_mon1
(11)