Time parsing, formatting, serialization, epoch conversion and current-clock helpers.
- Arguments:
- time struct.
- Does:
- zeroes all fields.
- Returns:
- no return value.
- Arguments:
- destination and source time structs.
- Does:
- copies the whole struct when both pointers are valid.
- Returns:
- no return value.
- Arguments:
- time struct.
- Does:
- normalizes the fields through
mktime()and writes the normalized values back.
- normalizes the fields through
- Returns:
- no return value.
- Arguments:
xtime_tandstruct tmobjects.
- Does:
- converts between the project struct and
struct tm.
- converts between the project struct and
- Returns:
- no return value.
- Arguments:
- destination
struct tm.
- destination
- Does:
- gets current local time and stores it as
struct tm.
- gets current local time and stores it as
- Returns:
- no return value.
- Arguments:
- destination clock struct containing seconds and nanoseconds.
- Does:
- reads the current real-time clock with:
clock_gettime(CLOCK_REALTIME)on Linux when available- Windows system time APIs
gettimeofday()elsewhere
- reads the current real-time clock with:
- Returns:
XSTDOKon success.XSTDERRon clock read failure.
- Arguments:
- destination
xtime_t.
- destination
- Does:
- reads current time, converts epoch seconds to local time and stores hundredths of a second in
nFraq.
- reads current time, converts epoch seconds to local time and stores hundredths of a second in
- Returns:
- current microseconds component.
- Arguments:
- none.
- Does:
- returns the current time as:
- microseconds component only
- epoch milliseconds
- epoch microseconds
- union-packed
xtime_t - manually serialized
uint64_t
- returns the current time as:
- Returns:
- the requested numeric representation.
- Arguments:
- destination buffer, size and desired format enum.
- Does:
- gets current time and formats it using one of the
XTime_To*()helpers.
- gets current time and formats it using one of the
- Returns:
- written length.
0for invalid args or unknown format.
- Arguments:
- raw year or
xtime_t.
- raw year or
- Does:
- checks leap-year rules.
- Returns:
1for leap year.0otherwise.
- Arguments:
- raw year/month or
xtime_t.
- raw year/month or
- Does:
- returns the number of days in the requested month.
- Returns:
28,29,30or31.
- Caveat:
- current February logic is reversed: leap years return
28and non-leap years return29.
- current February logic is reversed: leap years return
- Arguments:
- two time values and an optional scaling unit.
- Does:
- computes difference through
mktime()anddifftime(). - optionally rescales the result to years, months, weeks, days, hours or minutes using fixed constants.
- computes difference through
- Returns:
- floating-point difference value.
- Arguments:
- time struct and serialized integer.
- Does:
- manually packs or unpacks fields into a
uint64_t.
- manually packs or unpacks fields into a
- Returns:
- serializer returns the packed value.
- deserializer has no return value.
- Arguments:
- time struct and union-packed integer.
- Does:
- reinterprets the struct through
xtimeu_t.
- reinterprets the struct through
- Returns:
- packed integer from
ToU64(). - no return value from
FromU64().
- packed integer from
- Arguments:
- time struct, epoch value or ISO string.
- Does:
- converts between
xtime_tand local/UTC epoch seconds. FromEpoch()uses local time.ISOToEpochUTC()parses ISO then converts to UTC epoch seconds.
- converts between
- Returns:
- epoch value for converters.
0fromISOToEpochUTC()when parsing fails.
- Arguments:
- time struct, destination buffer and size.
- Does:
- writes one of the supported text forms:
- compact numeric
- dotted human format
- slash-separated format
- US-style format
- HTTP GMT string
- ISO
- ISO8601 UTC-with-
.000Z
- writes one of the supported text forms:
- Returns:
- written length from
xstrncpyf()orstrftime().
- written length from
- Arguments:
- destination time struct and source string.
- Does:
- clears the destination and parses the string with
sscanf().
- clears the destination and parses the string with
- Returns:
sscanf()field count.0when the source string is empty.
- Header status:
- declared in
xtime.h.
- declared in
- Implementation status:
- the source file implements
XTime_FromHStr()with a capitalS, notXTime_FromHstr().
- the source file implements
- Actual behavior of the implemented function:
- clears the destination and parses
%04d.%02d.%02d-%02d:%02d:%02d.%02d. - returns the
sscanf()field count or0for empty input.
- clears the destination and parses
-
FromEpoch()uses local time, not UTC. -
XTime_GetMonthDays()has reversed February leap-year logic in the current source. -
xtime.handxtime.cdisagree onXTime_FromHstrvsXTime_FromHStr. -
Decide explicitly whether your caller wants local time or UTC before mixing
FromEpoch(),ToEpochUTC()and HTTP/ISO helpers.