Time

struct UTime

Date and time.

Public Members

long long year

Year.

unsigned month

Month.

unsigned day

Day.

unsigned hour

Hour.

unsigned minute

Minute.

unsigned second

Second.

enum utime_unit

Time units.

Values:

enumerator UTIME_NANOSECONDS

Nanoseconds.

enumerator UTIME_MICROSECONDS

Microseconds.

enumerator UTIME_MILLISECONDS

Milliseconds.

enumerator UTIME_SECONDS

Seconds.

enumerator UTIME_MINUTES

Minutes.

enumerator UTIME_HOURS

Hours.

enumerator UTIME_DAYS

Days.

enumerator UTIME_MONTHS

Months.

enumerator UTIME_YEARS

Years.

typedef long long utime_stamp

Timestamp expressed as seconds since January 1 1970, 00:00:00.

typedef unsigned long long utime_ns

Nanoseconds type, suitable for storing CPU time.

bool utime_equals(UTime const *a, UTime const *b)

Checks whether the specified dates are equal.

Parameters:
  • a – First date.

  • b – Second date.

Returns:

True if the two dates are equal, false otherwise.

void utime_normalize_to_utc(UTime *time, int tz_hour, unsigned tz_minute)

Normalizes a date from the specified timezone to UTC.

Parameters:
  • time – Date to normalize.

  • tz_hour – Timezone offset hours.

  • tz_minute – Timezone offset minutes.

utime_stamp utime_to_timestamp(UTime const *time)

Converts the specified date into a timestamp.

Parameters:
  • time – Date to convert.

Returns:

Timestamp corresponding to the date.

UTime utime_from_timestamp(utime_stamp ts)

Converts the specified timestamp into a date.

Parameters:
  • ts – Timestamp to convert.

Returns:

Date corresponding to the timestamp.

void utime_add(UTime *time, long long quantity, utime_unit unit)

Adds a certain time interval to the specified date.

Parameters:
  • time – Date.

  • quantity – Quantity to add.

  • unit – Time unit.

long long utime_diff(UTime const *a, UTime const *b, utime_unit unit)

Returns the difference between the specified dates.

Parameters:
  • a – First date.

  • b – Second date.

  • unit – Time unit.

Returns:

Difference between the specified dates.

UString utime_to_string(UTime const *time)

Converts the specified date into a human readable string.

Note

The returned object must be destroyed by calling ustring_deinit().

Parameters:
  • time – Date.

Returns:

Human readable date string.

bool utime_from_string(UTime *time, UString const *string)

Parses a date from the specified string.

Note

The string must be in Y_M_D_H_M_S format, where each component is separated by any non-digit character. An optional timezone specifier can also be specified, in which case the date is automatically normalized to UTC. Examples of equivalent dates:

  • 1990/02/14 13:30:00

  • 1990-02-14T13:30:00Z

  • 1990 02 14 14.30.00+1:00

Parameters:
  • time[out] Date.

  • string – Date string.

Returns:

True if the string was parsed without errors, false otherwise.

bool utime_is_leap_year(long long year)

Checks whether the specified year is a leap year.

Parameters:
  • year – Year.

Returns:

True if the specified year is a leap year, false otherwise.

unsigned utime_days_in_month(long long year, unsigned month)

Returns the number of days in the specified month.

Parameters:
  • year – Year.

  • month – Month.

Returns:

Number of days in the specified month.

utime_stamp utime_get_timestamp(void)

Retrieves a timestamp expressed as seconds since January 1 1970, 00:00:00.

Returns:

Timestamp.

utime_ns utime_get_ns(void)

Retrieves a timestamp in nanoseconds.

Note

The timestamp is suitable for benchmarking purposes.

Returns:

Timestamp in nanoseconds.

utime_unit utime_interval_unit_auto(utime_ns t)

Returns an appropriate time unit for the specified time interval.

Parameters:
  • t – Time interval in nanoseconds.

Returns:

Appropriate time unit.

double utime_interval_convert(utime_ns t, utime_unit unit)

Converts a time interval according to the specified time unit.

Parameters:
  • t – Time interval.

  • unit – Time unit.

Returns:

Converted time interval.

UString utime_interval_to_string(utime_ns t, utime_unit unit)

Converts a time interval into a string formatted according to the specified time unit.

Note

The returned object must be destroyed by calling ustring_deinit().

Parameters:
  • t – Time interval in nanoseconds.

  • unit – Time unit.

Returns:

Time interval in string form.