|
PebbleOS v4.47.0-512-g5285d4236
|
Calendar arithmetic independent of the time zone and the RTC. More...
Data Structures | |
| struct | pbl_tm |
| structure containing broken-down time for expressing calendar time (ie. More... | |
Macros | |
| #define | PBL_TZ_LEN 6 |
Size of tm_zone in struct pbl_tm, including the terminating NUL. | |
| #define | PBL_TM_YEAR_ORIGIN 1900 |
Year that tm_year in struct pbl_tm counts from. | |
| #define | PBL_EPOCH_YEAR 1970 |
| Year of the Unix epoch. | |
| #define | PBL_EPOCH_WDAY 4 |
| Day of the week of the Unix epoch (Thursday), as an enum pbl_weekday value. | |
Typedefs | |
| typedef int32_t | pbl_time32_t |
Seconds since the epoch, as a 32-bit time_t holds them. | |
Enumerations | |
| enum | pbl_weekday { PBL_SUNDAY = 0 , PBL_MONDAY , PBL_TUESDAY , PBL_WEDNESDAY , PBL_THURSDAY , PBL_FRIDAY , PBL_SATURDAY } |
Day of the week, numbered like tm_wday. More... | |
Functions | |
| static bool | pbl_time_is_weekday (enum pbl_weekday day) |
| Check whether a day is a working day (Monday to Friday). | |
| static bool | pbl_time_is_weekend (enum pbl_weekday day) |
| Check whether a day is on the weekend (Saturday or Sunday). | |
| bool | pbl_time_is_leap_year (int year) |
| Check whether a Gregorian year is a leap year. | |
| int | pbl_time_days_in_month (int month, bool is_leap_year) |
| Get the number of days in a month. | |
| void | pbl_time_split_seconds (uint32_t seconds, uint32_t *days, uint32_t *hours, uint32_t *minutes, uint32_t *secs) |
| Split a duration into days, hours, minutes and seconds. | |
| int | pbl_time_display_hour (int hour, bool is_24h) |
| Convert an hour of the day to the hour shown on a clock. | |
| int | pbl_time_minute_of_day_adjust (int minute, int delta) |
| Add a delta to a minute of the day, wrapping around midnight. | |
| void | pbl_time_breakdown (time_t t, struct pbl_tm *tm) |
| Fill the calendar fields of a struct pbl_tm from seconds since the epoch. | |
| struct pbl_tm * | pbl_gmtime_r (const time_t *timep, struct pbl_tm *result) |
| Convert seconds since the epoch to broken-down UTC time. | |
| time_t | pbl_mktime (struct pbl_tm *tb) |
| Convert broken-down time to seconds since the epoch. | |
| static pbl_time32_t | pbl_time_to_time32 (time_t t) |
| Narrow a time to 32 bits. | |
| time_t | pbl_time_from_time32 (pbl_time32_t t, time_t reference) |
| Widen a 32-bit time. | |
Calendar arithmetic independent of the time zone and the RTC.
| struct pbl_tm |
structure containing broken-down time for expressing calendar time (ie.
Year, Month, Day of Month, Hour of Day) and timezone information
| Data Fields | ||
|---|---|---|
| int | tm_gmtoff |
Total seconds east of UTC, DST included. tm_isdst is an indicator only – never add it to this value. |
| int | tm_hour |
Hours. [0-23] |
| int | tm_isdst |
DST. [-1/0/1] |
| int | tm_mday |
Day. [1-31] |
| int | tm_min |
Minutes. [0-59] |
| int | tm_mon |
Month. [0-11] |
| int | tm_sec |
Seconds. [0-60] (1 leap second) |
| int | tm_wday |
Day of week. [0-6] |
| int | tm_yday |
Days in year.[0-365] |
| int | tm_year |
Years since 1900 |
| char | tm_zone[PBL_TZ_LEN] |
Timezone abbreviation |
| #define PBL_EPOCH_WDAY 4 |
Day of the week of the Unix epoch (Thursday), as an enum pbl_weekday value.
| #define PBL_EPOCH_YEAR 1970 |
Year of the Unix epoch.
| #define PBL_TM_YEAR_ORIGIN 1900 |
Year that tm_year in struct pbl_tm counts from.
| #define PBL_TZ_LEN 6 |
Size of tm_zone in struct pbl_tm, including the terminating NUL.
| typedef int32_t pbl_time32_t |
Seconds since the epoch, as a 32-bit time_t holds them.
For interfaces that keep a 32-bit time_t whatever the width of the native one.
| enum pbl_weekday |
Convert seconds since the epoch to broken-down UTC time.
| timep | Seconds since the Unix epoch. | |
| [out] | result | Broken-down time, in the UTC zone. |
result. | time_t pbl_mktime | ( | struct pbl_tm * | tb | ) |
Convert broken-down time to seconds since the epoch.
Fields out of their range are carried over, and tm_gmtoff is subtracted from the result.
| [in,out] | tb | Broken-down time, replaced by the UTC broken-down time of the result. |
| void pbl_time_breakdown | ( | time_t | t, |
| struct pbl_tm * | tm | ||
| ) |
Fill the calendar fields of a struct pbl_tm from seconds since the epoch.
Sets tm_sec to tm_yday. The DST, offset and zone fields are left untouched.
| t | Seconds since the Unix epoch. | |
| [out] | tm | Broken-down time. |
| int pbl_time_days_in_month | ( | int | month, |
| bool | is_leap_year | ||
| ) |
Get the number of days in a month.
| month | Month of the year, 1 (January) to 12 (December). |
| is_leap_year | Whether the year is a leap year. |
| int pbl_time_display_hour | ( | int | hour, |
| bool | is_24h | ||
| ) |
Convert an hour of the day to the hour shown on a clock.
| hour | Hour of the day, 0 to 23. |
| is_24h | Whether the clock uses the 24-hour format. |
hour on a 24-hour clock, or 1 to 12 on a 12-hour clock. | time_t pbl_time_from_time32 | ( | pbl_time32_t | t, |
| time_t | reference | ||
| ) |
Widen a 32-bit time.
Up to 2038 (while reference fits in 32 bits) this is a plain sign extension. Later, the result is the time closest to reference with the same low 32 bits, so recent times keep their meaning after they wrap.
| t | 32-bit time. |
| reference | Current time, to place t relative to. |
t as seconds since the Unix epoch. | bool pbl_time_is_leap_year | ( | int | year | ) |
Check whether a Gregorian year is a leap year.
| year | Full year, e.g. 2024. |
|
inlinestatic |
Check whether a day is a working day (Monday to Friday).
| day | Day of the week. |
References PBL_FRIDAY, and PBL_MONDAY.
|
inlinestatic |
Check whether a day is on the weekend (Saturday or Sunday).
| day | Day of the week. |
References PBL_SATURDAY, and PBL_SUNDAY.
| int pbl_time_minute_of_day_adjust | ( | int | minute, |
| int | delta | ||
| ) |
Add a delta to a minute of the day, wrapping around midnight.
| minute | Minute of the day, 0 to 1439. |
| delta | Minutes to add, at most one day in either direction. |
| void pbl_time_split_seconds | ( | uint32_t | seconds, |
| uint32_t * | days, | ||
| uint32_t * | hours, | ||
| uint32_t * | minutes, | ||
| uint32_t * | secs | ||
| ) |
Split a duration into days, hours, minutes and seconds.
| seconds | Duration in seconds. | |
| [out] | days | Whole days. |
| [out] | hours | Remaining hours, 0 to 23. |
| [out] | minutes | Remaining minutes, 0 to 59. |
| [out] | secs | Remaining seconds, 0 to 59. |
|
inlinestatic |
Narrow a time to 32 bits.
Keeps the low 32 bits, so times past 2038 wrap like a 32-bit time_t does.
| t | Seconds since the Unix epoch. |
t as a 32-bit time.