PebbleOS
Loading...
Searching...
No Matches
Data Structures | Macros | Functions

Timezone, DST and local time conversions. More...

Data Structures

struct  TimezoneInfo
 Timezone information, small enough to be kept in RTC registers. More...
 

Macros

#define DSTID_BRAZIL   6
 DST rule index of Brazil.
 
#define DSTID_LORDHOWE   20
 DST rule index of Lord Howe Island, whose DST offset is half an hour.
 

Functions

void time_get_timezone_abbr (char *out_buf, time_t utc_time)
 Get the timezone abbreviation in effect at a given time.
 
int32_t time_get_gmtoffset (void)
 Get the offset of the timezone from UTC, without DST.
 
bool time_get_isdst (time_t utc_time)
 Check whether a time falls within the DST period.
 
int32_t time_get_dstoffset (void)
 Get the offset added during DST.
 
time_t time_get_dst_start (void)
 Get the start of the DST period.
 
time_t time_utc_to_local (time_t utc_time)
 Convert UTC time, as returned by rtc_get_time(), to local time.
 
time_t time_local_to_utc (time_t local_time)
 Convert local time to UTC time.
 
void time_util_update_timezone (const TimezoneInfo *tz_info)
 Set the current timezone.
 
time_t time_util_get_midnight_of (time_t ts)
 Get the local midnight starting the day of a time.
 
bool time_util_range_spans_day (time_t start, time_t end, time_t start_of_day)
 Check whether a range covers a whole day.
 
time_t sys_time_utc_to_local (time_t t)
 Syscall wrapper of time_utc_to_local(), for unprivileged code.
 
time_t time_util_utc_to_local_offset (void)
 Get the current offset of local time from UTC, including DST.
 
uint16_t time_util_get_day (time_t utc_sec)
 Get the local day index of a time.
 
enum pbl_weekday time_util_get_day_in_week (time_t utc_sec)
 Get the local day of the week of a time.
 
int time_util_get_minute_of_day (time_t utc_sec)
 Get the local minute of the day of a time.
 
time_t time_start_of_today (void)
 Return the UTC time that corresponds to the start of today (midnight).
 
uint32_t time_get_uptime_seconds (void)
 Get the time since boot.
 

Detailed Description

Timezone, DST and local time conversions.

Holds the current timezone and its DST period, set from the phone or the timezone database, and converts between UTC and local time accordingly.


Data Structure Documentation

◆ TimezoneInfo

struct TimezoneInfo

Timezone information, small enough to be kept in RTC registers.

Data Fields
time_t dst_end UTC timestamp of the end of the DST period, 0 if none.
uint8_t dst_id DST rule index.
time_t dst_start UTC timestamp of the start of the DST period, 0 if none.
int16_t timezone_id Olson index of the timezone.
int32_t tm_gmtoff Offset from UTC in seconds, without DST.
char tm_zone[TZ_LEN - 1] Abbreviation, up to 5 characters, not NUL terminated.

A * is replaced by D or S depending on DST.

Macro Definition Documentation

◆ DSTID_BRAZIL

#define DSTID_BRAZIL   6

DST rule index of Brazil.

DST ids index the rules generated by tools/timezones.py from the Olson database; do not change them independently. Ids not listed here switch by one hour on the same spring and autumn days every year. Morocco's rules, which suspend DST for Ramadan, are not handled correctly.

◆ DSTID_LORDHOWE

#define DSTID_LORDHOWE   20

DST rule index of Lord Howe Island, whose DST offset is half an hour.

Function Documentation

◆ sys_time_utc_to_local()

time_t sys_time_utc_to_local ( time_t  t)

Syscall wrapper of time_utc_to_local(), for unprivileged code.

Parameters
tUTC time.
Returns
Local time.

◆ time_get_dst_start()

time_t time_get_dst_start ( void  )

Get the start of the DST period.

Returns
UTC timestamp, 0 if none.

◆ time_get_dstoffset()

int32_t time_get_dstoffset ( void  )

Get the offset added during DST.

Returns
Offset in seconds, usually one hour.

◆ time_get_gmtoffset()

int32_t time_get_gmtoffset ( void  )

Get the offset of the timezone from UTC, without DST.

Returns
Offset in seconds.

◆ time_get_isdst()

bool time_get_isdst ( time_t  utc_time)

Check whether a time falls within the DST period.

Parameters
utc_timeUTC time.
Returns
True if DST applies.

◆ time_get_timezone_abbr()

void time_get_timezone_abbr ( char *  out_buf,
time_t  utc_time 
)

Get the timezone abbreviation in effect at a given time.

Parameters
[out]out_bufBuffer of TZ_LEN bytes, receives a NUL terminated abbreviation.
utc_timeTime used to decide whether DST applies.

◆ time_get_uptime_seconds()

uint32_t time_get_uptime_seconds ( void  )

Get the time since boot.

Based on the tick count, so unaffected by changes of the wall-clock time.

Returns
Uptime in seconds.

◆ time_local_to_utc()

time_t time_local_to_utc ( time_t  local_time)

Convert local time to UTC time.

Ambiguous during the hour repeated when DST ends.

Parameters
local_timeLocal time.
Returns
UTC time.

◆ time_start_of_today()

time_t time_start_of_today ( void  )

Return the UTC time that corresponds to the start of today (midnight).

Returns
the UTC time corresponding to the start of today (midnight)

◆ time_utc_to_local()

time_t time_utc_to_local ( time_t  utc_time)

Convert UTC time, as returned by rtc_get_time(), to local time.

Parameters
utc_timeUTC time.
Returns
Local time.

◆ time_util_get_day()

uint16_t time_util_get_day ( time_t  utc_sec)

Get the local day index of a time.

The index increments every day at local midnight.

Parameters
utc_secUTC time.
Returns
Days since the epoch, in local time.

◆ time_util_get_day_in_week()

enum pbl_weekday time_util_get_day_in_week ( time_t  utc_sec)

Get the local day of the week of a time.

Parameters
utc_secUTC time.
Returns
Day of the week.

◆ time_util_get_midnight_of()

time_t time_util_get_midnight_of ( time_t  ts)

Get the local midnight starting the day of a time.

Parameters
tsUTC time.
Returns
UTC time of the local midnight.

◆ time_util_get_minute_of_day()

int time_util_get_minute_of_day ( time_t  utc_sec)

Get the local minute of the day of a time.

Parameters
utc_secUTC time.
Returns
Minutes since local midnight.

◆ time_util_range_spans_day()

bool time_util_range_spans_day ( time_t  start,
time_t  end,
time_t  start_of_day 
)

Check whether a range covers a whole day.

Parameters
startStart of the range.
endEnd of the range.
start_of_dayStart of the day.
Returns
True if the range covers the 24 hours from start_of_day.

◆ time_util_update_timezone()

void time_util_update_timezone ( const TimezoneInfo *  tz_info)

Set the current timezone.

Parameters
tz_infoNew timezone, including its DST period.

◆ time_util_utc_to_local_offset()

time_t time_util_utc_to_local_offset ( void  )

Get the current offset of local time from UTC, including DST.

Returns
Offset in seconds.