picofuse

date.h
Go to the documentation of this file.
1 
7 #pragma once
8 
9 #include <stdbool.h>
10 #include <stddef.h>
11 #include <stdint.h>
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
18 // TYPES
19 
25 typedef struct sys_date_t {
26  int64_t seconds;
27  int32_t nanoseconds;
28  int32_t tzoffset;
29 } sys_date_t;
30 
35 typedef enum {
47 
49 // METHODS
50 
61 bool sys_date_get_now(sys_date_t *date);
62 
69 bool sys_date_set_now(const sys_date_t *date);
70 
80 bool sys_date_get_time_utc(const sys_date_t *date, uint8_t *hours,
81  uint8_t *minutes, uint8_t *seconds);
82 
92 bool sys_date_get_time_local(const sys_date_t *date, uint8_t *hours,
93  uint8_t *minutes, uint8_t *seconds);
94 
105 bool sys_date_get_date_utc(const sys_date_t *date, uint16_t *year,
106  uint8_t *month, uint8_t *day, uint8_t *weekday);
107 
118 bool sys_date_get_date_local(const sys_date_t *date, uint16_t *year,
119  uint8_t *month, uint8_t *day, uint8_t *weekday);
120 
130 bool sys_date_set_time_utc(sys_date_t *date, uint8_t hours, uint8_t minutes,
131  uint8_t seconds);
132 
142 bool sys_date_set_date_utc(sys_date_t *date, uint16_t year, uint8_t month,
143  uint8_t day);
144 
153 int64_t sys_date_compare_ns(const sys_date_t *start, const sys_date_t *end);
154 
167 size_t sys_date_to_string(const sys_date_t *date, sys_date_format_t format,
168  char *buf, size_t buf_size);
169 
172 #ifdef __cplusplus
173 }
174 #endif
"2026-09-06 11:37:05" - a plain, sortable form for logs/debug output, in whatever timezone tzoffset r...
Definition: date.h:43
struct sys_date_t sys_date_t
Represents a system date and time.
bool sys_date_get_time_local(const sys_date_t *date, uint8_t *hours, uint8_t *minutes, uint8_t *seconds)
Extract local time components from a date.
size_t sys_date_to_string(const sys_date_t *date, sys_date_format_t format, char *buf, size_t buf_size)
Format a date as a human-readable string.
bool sys_date_get_date_local(const sys_date_t *date, uint16_t *year, uint8_t *month, uint8_t *day, uint8_t *weekday)
Extract local date components from a date.
int64_t seconds
Seconds since the Unix epoch in UTC.
Definition: date.h:26
bool sys_date_get_date_utc(const sys_date_t *date, uint16_t *year, uint8_t *month, uint8_t *day, uint8_t *weekday)
Extract UTC date components from a date.
bool sys_date_set_date_utc(sys_date_t *date, uint16_t year, uint8_t month, uint8_t day)
Set UTC date components on an existing date.
bool sys_date_set_now(const sys_date_t *date)
Set the current system date and time.
bool sys_date_get_now(sys_date_t *date)
Get the current system date and time.
int32_t nanoseconds
Fractional seconds in nanoseconds.
Definition: date.h:27
sys_date_format_t
Common human-readable date/time string formats.
Definition: date.h:35
"Sun, 06 Sep 2026 11:37:05 GMT" - the HTTP-date format (RFC 7231 7.1.1.1), always rendered in UTC reg...
Definition: date.h:39
int32_t tzoffset
Timezone offset in seconds east of UTC.
Definition: date.h:28
int64_t sys_date_compare_ns(const sys_date_t *start, const sys_date_t *end)
Compare two dates in nanoseconds.
Represents a system date and time.
Definition: date.h:25
bool sys_date_get_time_utc(const sys_date_t *date, uint8_t *hours, uint8_t *minutes, uint8_t *seconds)
Extract UTC time components from a date.
"2026-09-06T11:37:05Z" - or, when tzoffset is non-zero, an explicit "+HH:MM"/"-HH:MM" offset instead ...
Definition: date.h:36
bool sys_date_set_time_utc(sys_date_t *date, uint8_t hours, uint8_t minutes, uint8_t seconds)
Set UTC time components on an existing date.