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 and times are equal.

Parameters:
  • a – First date and time.

  • b – Second date and time.

Returns:

True if the two dates and times are equal, false otherwise.

utime_stamp utime_to_timestamp(UTime const *time)

Converts the specified UTC date abd time into a timestamp.

Parameters:
  • time – Date and time to convert.

Returns:

Corresponding timestamp.

UTime utime_now(void)

Gets the current UTC date and time.

Returns:

Current UTC date and time.

UTime utime_local(void)

Gets the current local date and time.

Returns:

Current local date and time.

UTime utime_from_timestamp(utime_stamp ts)

Converts the specified timestamp into a UTC date and time.

Parameters:
  • ts – Timestamp to convert.

Returns:

Corresponding UTC date and time.

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

Adds a certain time interval to the specified date and time.

Parameters:
  • time – Date and time.

  • quantity – Quantity to add.

  • unit – Time unit.

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

Transforms a date and time from the specified timezone to UTC.

Parameters:
  • time – Date and time to transform.

  • tz_hour – Timezone offset hours.

  • tz_minute – Timezone offset minutes.

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

Transforms a date and time from UTC to the specified timezone.

Parameters:
  • time – Date and time to transform.

  • tz_hour – Timezone offset hours.

  • tz_minute – Timezone offset minutes.

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

Normalizes a date and time from the specified timezone to UTC.

Deprecated:

Use utime_to_utc() instead.

Parameters:
  • time – Date and time to normalize.

  • tz_hour – Timezone offset hours.

  • tz_minute – Timezone offset minutes.

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

Returns the difference between the specified dates and times.

Parameters:
  • a – First date and time.

  • b – Second date and time.

  • unit – Time unit.

Returns:

Difference between the specified dates and times.

UString utime_to_string(UTime const *time)

Converts the specified date and time into a human readable string.

Note

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

Parameters:
  • time – Date and time.

Returns:

Human readable string.

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

Parses a date and time 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 and time.

  • 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.