|
solidc
Robust collection of general-purpose cross-platform C libraries and data structures designed for rapid and safe development in C
|
Extended time utilities and high-precision timing functions. More...
#include <stdbool.h>#include <stdint.h>#include <time.h>Go to the source code of this file.
Classes | |
| struct | xtime_t |
Macros | |
| #define | XTIME_FMT_ISO8601 "%Y-%m-%dT%H:%M:%S" |
Enumerations | |
| enum | xtime_error_t |
Extended time utilities and high-precision timing functions.
Cross-platform time parsing and formatting library.
Provides fast, safe time parsing and formatting with comprehensive error handling. All functions are thread-safe when operating on separate xtime_t instances.
Definition in file xtime.h.
| #define XTIME_FMT_ISO8601 "%Y-%m-%dT%H:%M:%S" |
| enum xtime_error_t |
| xtime_error_t xtime_add_days | ( | xtime_t * | t, |
| int64_t | days | ||
| ) |
Adds a duration in days to the time.
| t | Pointer to xtime_t to modify. |
| days | Days to add (can be negative). |
Definition at line 584 of file xtime.c.
References xtime_add_seconds().
Referenced by xtime_end_of_month(), xtime_end_of_year(), xtime_start_of_month(), xtime_start_of_week(), and xtime_start_of_year().
| xtime_error_t xtime_add_hours | ( | xtime_t * | t, |
| int64_t | hours | ||
| ) |
Adds a duration in hours to the time.
| t | Pointer to xtime_t to modify. |
| hours | Hours to add (can be negative). |
Definition at line 576 of file xtime.c.
References xtime_add_seconds().
| xtime_error_t xtime_add_microseconds | ( | xtime_t * | t, |
| int64_t | micros | ||
| ) |
Adds a duration in microseconds to the time.
| t | Pointer to xtime_t to modify. |
| micros | Microseconds to add (can be negative). |
Definition at line 552 of file xtime.c.
References xtime_add_nanoseconds().
| xtime_error_t xtime_add_milliseconds | ( | xtime_t * | t, |
| int64_t | millis | ||
| ) |
Adds a duration in milliseconds to the time.
| t | Pointer to xtime_t to modify. |
| millis | Milliseconds to add (can be negative). |
Definition at line 560 of file xtime.c.
References xtime_add_nanoseconds().
| xtime_error_t xtime_add_minutes | ( | xtime_t * | t, |
| int64_t | minutes | ||
| ) |
Adds a duration in minutes to the time.
| t | Pointer to xtime_t to modify. |
| minutes | Minutes to add (can be negative). |
Definition at line 568 of file xtime.c.
References xtime_add_seconds().
| xtime_error_t xtime_add_months | ( | xtime_t * | t, |
| int | months | ||
| ) |
Adds months to the time, accounting for varying month lengths. If the resulting date is invalid (e.g., Jan 31 + 1 month = Feb 31), adjusts to the last valid day of that month.
| t | Pointer to xtime_t to modify. |
| months | Months to add (can be negative). |
| xtime_error_t xtime_add_nanoseconds | ( | xtime_t * | t, |
| int64_t | nanos | ||
| ) |
Adds a duration in nanoseconds to the time. Handles overflow into seconds automatically.
| t | Pointer to xtime_t to modify. |
| nanos | Nanoseconds to add (can be negative). |
Definition at line 529 of file xtime.c.
Referenced by xtime_add_microseconds(), and xtime_add_milliseconds().
| xtime_error_t xtime_add_seconds | ( | xtime_t * | t, |
| int64_t | seconds | ||
| ) |
Adds seconds to a time value.
| t | Pointer to xtime_t to modify. |
| seconds | Number of seconds to add (can be negative). |
Definition at line 461 of file xtime.c.
Referenced by xtime_add_days(), xtime_add_hours(), and xtime_add_minutes().
| xtime_error_t xtime_add_years | ( | xtime_t * | t, |
| int | years | ||
| ) |
Adds years to the time, accounting for leap years and month boundaries. If the resulting date is invalid (e.g., Feb 29 in non-leap year), adjusts to the last valid day of that month.
| t | Pointer to xtime_t to modify. |
| years | Years to add (can be negative). |
| xtime_error_t xtime_diff | ( | const xtime_t * | t1, |
| const xtime_t * | t2, | ||
| double * | diff | ||
| ) |
| xtime_error_t xtime_diff_days | ( | const xtime_t * | t1, |
| const xtime_t * | t2, | ||
| int64_t * | days | ||
| ) |
| xtime_error_t xtime_diff_hours | ( | const xtime_t * | t1, |
| const xtime_t * | t2, | ||
| int64_t * | hours | ||
| ) |
| xtime_error_t xtime_diff_micros | ( | const xtime_t * | t1, |
| const xtime_t * | t2, | ||
| int64_t * | micros | ||
| ) |
Calculates the duration between two times in microseconds. Returns t1 - t2 (positive if t1 is after t2).
| t1 | First time. |
| t2 | Second time. |
| micros | Output: difference in microseconds. |
Definition at line 716 of file xtime.c.
References xtime_diff_nanos().
| xtime_error_t xtime_diff_millis | ( | const xtime_t * | t1, |
| const xtime_t * | t2, | ||
| int64_t * | millis | ||
| ) |
Calculates the duration between two times in milliseconds. Returns t1 - t2 (positive if t1 is after t2).
| t1 | First time. |
| t2 | Second time. |
| millis | Output: difference in milliseconds. |
Definition at line 732 of file xtime.c.
References xtime_diff_nanos().
| xtime_error_t xtime_diff_minutes | ( | const xtime_t * | t1, |
| const xtime_t * | t2, | ||
| int64_t * | minutes | ||
| ) |
| xtime_error_t xtime_diff_nanos | ( | const xtime_t * | t1, |
| const xtime_t * | t2, | ||
| int64_t * | nanos | ||
| ) |
Calculates the duration between two times in nanoseconds. Returns t1 - t2 (positive if t1 is after t2).
| t1 | First time. |
| t2 | Second time. |
| nanos | Output: difference in nanoseconds. |
Definition at line 703 of file xtime.c.
Referenced by xtime_diff_micros(), and xtime_diff_millis().
| xtime_error_t xtime_diff_seconds | ( | const xtime_t * | t1, |
| const xtime_t * | t2, | ||
| int64_t * | seconds | ||
| ) |
| xtime_error_t xtime_end_of_day | ( | const xtime_t * | t, |
| xtime_t * | result | ||
| ) |
Returns a new time representing the end of the day (23:59:59.999999999). Does not modify the original time.
| t | Input time. |
| result | Output: end of day. |
Definition at line 934 of file xtime.c.
References xtime_truncate_to_day().
| xtime_error_t xtime_end_of_month | ( | const xtime_t * | t, |
| xtime_t * | result | ||
| ) |
Returns a new time representing the end of the month (last day, 23:59:59.999999999). Does not modify the original time.
| t | Input time. |
| result | Output: end of month. |
Definition at line 954 of file xtime.c.
References xtime_add_days(), and xtime_truncate_to_day().
| xtime_error_t xtime_end_of_year | ( | const xtime_t * | t, |
| xtime_t * | result | ||
| ) |
Returns a new time representing the end of the year (Dec 31, 23:59:59.999999999). Does not modify the original time.
| t | Input time. |
| result | Output: end of year. |
Definition at line 993 of file xtime.c.
References xtime_add_days(), and xtime_truncate_to_day().
| xtime_error_t xtime_format | ( | const xtime_t * | t, |
| const char * | format, | ||
| char * | buf, | ||
| size_t | buflen | ||
| ) |
Formats time according to the specified format string. Uses local timezone if time has timezone info, otherwise uses UTC.
| t | Pointer to xtime_t containing time to format. |
| format | Format specifier (supports standard strftime formats). |
| buf | Output buffer for formatted string. |
| buflen | Size of output buffer. |
| xtime_error_t xtime_format_utc | ( | const xtime_t * | t, |
| const char * | format, | ||
| char * | buf, | ||
| size_t | buflen | ||
| ) |
Formats time in UTC regardless of timezone information.
| t | Pointer to xtime_t containing time to format. |
| format | Format specifier (supports standard strftime formats). |
| buf | Output buffer for formatted string. |
| buflen | Size of output buffer. |
| xtime_error_t xtime_from_unix | ( | int64_t | timestamp, |
| xtime_t * | t | ||
| ) |
| xtime_error_t xtime_init | ( | xtime_t * | t | ) |
Initializes an xtime_t structure to zero.
| t | Pointer to xtime_t to initialize. |
Definition at line 48 of file xtime.c.
References xtime_init().
Referenced by xtime_init(), and xtime_parse().
| bool xtime_is_leap_year | ( | const xtime_t * | t | ) |
| xtime_error_t xtime_now | ( | xtime_t * | t | ) |
Gets current system time with nanosecond precision where available. Automatically captures local timezone offset.
| t | Pointer to xtime_t to store current time. |
Definition at line 94 of file xtime.c.
Referenced by xtime_utc_now().
| xtime_error_t xtime_parse | ( | const char * | str, |
| const char * | format, | ||
| xtime_t * | t | ||
| ) |
Parses a time string according to the specified format. Supports strptime-style format specifiers plus extensions for nanoseconds and timezone.
| str | The time string to parse. |
| format | Format specifier (supports standard strptime formats). |
| t | Pointer to xtime_t to store parsed time. |
Definition at line 220 of file xtime.c.
References xtime_init().
| xtime_error_t xtime_start_of_month | ( | const xtime_t * | t, |
| xtime_t * | result | ||
| ) |
Returns a new time representing the start of the month (day 1, 00:00:00). Does not modify the original time.
| t | Input time. |
| result | Output: start of month. |
Definition at line 880 of file xtime.c.
References xtime_add_days(), and xtime_truncate_to_day().
| xtime_error_t xtime_start_of_week | ( | const xtime_t * | t, |
| xtime_t * | result | ||
| ) |
Returns a new time representing the start of the week (Monday 00:00:00). Does not modify the original time.
| t | Input time. |
| result | Output: start of week. |
Definition at line 852 of file xtime.c.
References xtime_add_days(), and xtime_truncate_to_day().
| xtime_error_t xtime_start_of_year | ( | const xtime_t * | t, |
| xtime_t * | result | ||
| ) |
Returns a new time representing the start of the year (Jan 1, 00:00:00). Does not modify the original time.
| t | Input time. |
| result | Output: start of year. |
Definition at line 907 of file xtime.c.
References xtime_add_days(), and xtime_truncate_to_day().
| const char * xtime_strerror | ( | xtime_error_t | err | ) |
| xtime_error_t xtime_to_json | ( | const xtime_t * | t, |
| char * | buf, | ||
| size_t | buflen | ||
| ) |
Formats time into a JSON-compatible ISO 8601 string (RFC 3339). Format: "YYYY-MM-DDTHH:MM:SS.nnnnnnnnnZ" (or +HH:MM)
| t | Pointer to xtime_t to convert. |
| buf | Output buffer. |
| buflen | Size of output buffer (Recommended: at least 40 chars). |
| int64_t xtime_to_unix | ( | const xtime_t * | t | ) |
| xtime_error_t xtime_truncate_to_day | ( | xtime_t * | t | ) |
Rounds time down to the start of the current day (00:00:00.000000000). Preserves timezone information.
| t | Pointer to xtime_t to modify. |
Definition at line 839 of file xtime.c.
Referenced by xtime_end_of_day(), xtime_end_of_month(), xtime_end_of_year(), xtime_start_of_month(), xtime_start_of_week(), and xtime_start_of_year().
| xtime_error_t xtime_truncate_to_hour | ( | xtime_t * | t | ) |
| xtime_error_t xtime_truncate_to_minute | ( | xtime_t * | t | ) |
| xtime_error_t xtime_truncate_to_second | ( | xtime_t * | t | ) |
| xtime_error_t xtime_utc_now | ( | xtime_t * | t | ) |
Gets current system time in UTC (no timezone offset).
| t | Pointer to xtime_t to store current time. |
Definition at line 150 of file xtime.c.
References xtime_now().