Common RTC helper functions.
More...
Common RTC helper functions.
|
void | rtc_tm_normalize (struct tm *time) |
| Normalize the time struct.
|
|
int | rtc_tm_compare (const struct tm *a, const struct tm *b) |
| Compare two time structs.
|
|
uint32_t | rtc_mktime (const struct tm *t) |
| Convert time struct into timestamp.
|
|
void | rtc_localtime (uint32_t time, struct tm *t) |
| Converts an RTC timestamp into a time struct.
|
|
bool | rtc_tm_valid (const struct tm *t) |
| Verify that a time struct t contains valid data.
|
|
◆ rtc_localtime()
void rtc_localtime |
( |
uint32_t |
time, |
|
|
struct tm * |
t |
|
) |
| |
Converts an RTC timestamp into a time struct.
- Parameters
-
[in] | time | elapsed seconds since RIOT_EPOCH |
[out] | t | the corresponding timestamp |
◆ rtc_mktime()
uint32_t rtc_mktime |
( |
const struct tm * |
t | ) |
|
Convert time struct into timestamp.
- Precondition
- The time struct t is assumed to be normalized. Use rtc_tm_normalize to normalize a struct tm that has been manually edited.
- Parameters
-
[in] | t | The time struct to convert |
- Returns
- elapsed seconds since
RIOT_EPOCH
◆ rtc_tm_compare()
int rtc_tm_compare |
( |
const struct tm * |
a, |
|
|
const struct tm * |
b |
|
) |
| |
Compare two time structs.
- Precondition
- The time structs
a
and b
are assumed to be normalized. Use rtc_tm_normalize to normalize a struct tm that has been manually edited.
- Parameters
-
[in] | a | The first time struct. |
[in] | b | The second time struct. |
- Returns
- an integer < 0 if a is earlier than b
-
an integer > 0 if a is later than b
-
0 if a and b are equal
◆ rtc_tm_normalize()
void rtc_tm_normalize |
( |
struct tm * |
time | ) |
|
Normalize the time struct.
- Note
- The function modifies the fields of the tm structure as follows: If structure members are outside their valid interval, they will be normalized. So that, for example, 40 October is changed into 9 November.
If RTC_NORMALIZE_COMPAT is 1 tm_wday
and tm_yday
are set to values determined from the contents of the other fields.
- Parameters
-
time | Pointer to the struct to normalize. |
◆ rtc_tm_valid()
bool rtc_tm_valid |
( |
const struct tm * |
t | ) |
|
Verify that a time struct t
contains valid data.
- Note
- This function checks whether the fields of the struct
t
are positive and within the bounds set by rtc_tm_normalize.
- Parameters
-
[in] | t | The struct to be checked. |
- Returns
- true when valid, false if not