RTC helpers

Common RTC helper functions. More...

Detailed Description

Common RTC helper functions.

Files

file  rtc_utils.h
 

Functions

void rtc_tm_normalize (struct tm *time)
 Normalize the time struct. More...
 
int rtc_tm_compare (const struct tm *a, const struct tm *b)
 Compare two time structs. More...
 
uint32_t rtc_mktime (struct tm *t)
 Convert time struct into timestamp. More...
 
void rtc_localtime (uint32_t time, struct tm *t)
 Converts an RTC timestamp into a time struct. More...
 
bool rtc_tm_valid (const struct tm *t)
 Verify that a time struct t contains valid data. More...
 

Function Documentation

◆ rtc_localtime()

void rtc_localtime ( uint32_t  time,
struct tm *  t 
)

Converts an RTC timestamp into a time struct.

Parameters
[in]timeelapsed seconds since RIOT_EPOCH
[out]tthe corresponding timestamp

◆ rtc_mktime()

uint32_t rtc_mktime ( struct tm *  t)

Convert time struct into timestamp.

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]tThe 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]aThe first time struct.
[in]bThe 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
timePointer 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]tThe struct to be checked.
Returns
true when valid, false if not