PebbleOS
Loading...
Searching...
No Matches
Macros | Enumerations | Functions
Calendar time

Calendar arithmetic independent of the time zone and the RTC. More...

Macros

#define PBL_TM_YEAR_ORIGIN   1900
 Year that tm_year in struct 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.
 

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 tm *tm)
 Fill the calendar fields of a struct tm from seconds since the epoch.
 

Detailed Description

Calendar arithmetic independent of the time zone and the RTC.

Macro Definition Documentation

◆ PBL_EPOCH_WDAY

#define PBL_EPOCH_WDAY   4

Day of the week of the Unix epoch (Thursday), as an enum pbl_weekday value.

◆ PBL_EPOCH_YEAR

#define PBL_EPOCH_YEAR   1970

Year of the Unix epoch.

◆ PBL_TM_YEAR_ORIGIN

#define PBL_TM_YEAR_ORIGIN   1900

Year that tm_year in struct tm counts from.

Enumeration Type Documentation

◆ pbl_weekday

Day of the week, numbered like tm_wday.

Enumerator
PBL_SUNDAY 

Sunday.

PBL_MONDAY 

Monday.

PBL_TUESDAY 

Tuesday.

PBL_WEDNESDAY 

Wednesday.

PBL_THURSDAY 

Thursday.

PBL_FRIDAY 

Friday.

PBL_SATURDAY 

Saturday.

Function Documentation

◆ pbl_time_breakdown()

void pbl_time_breakdown ( time_t  t,
struct tm *  tm 
)

Fill the calendar fields of a struct tm from seconds since the epoch.

Sets tm_sec to tm_yday. The DST, offset and zone fields are left untouched.

Parameters
tSeconds since the Unix epoch.
[out]tmBroken-down time.

◆ pbl_time_days_in_month()

int pbl_time_days_in_month ( int  month,
bool  is_leap_year 
)

Get the number of days in a month.

Parameters
monthMonth of the year, 1 (January) to 12 (December).
is_leap_yearWhether the year is a leap year.
Returns
Number of days, 28 to 31.

◆ pbl_time_display_hour()

int pbl_time_display_hour ( int  hour,
bool  is_24h 
)

Convert an hour of the day to the hour shown on a clock.

Parameters
hourHour of the day, 0 to 23.
is_24hWhether the clock uses the 24-hour format.
Returns
hour on a 24-hour clock, or 1 to 12 on a 12-hour clock.

◆ pbl_time_is_leap_year()

bool pbl_time_is_leap_year ( int  year)

Check whether a Gregorian year is a leap year.

Parameters
yearFull year, e.g. 2024.
Returns
true for a leap year.

◆ pbl_time_is_weekday()

static bool pbl_time_is_weekday ( enum pbl_weekday  day)
inlinestatic

Check whether a day is a working day (Monday to Friday).

Parameters
dayDay of the week.
Returns
true for Monday to Friday.

References PBL_FRIDAY, and PBL_MONDAY.

◆ pbl_time_is_weekend()

static bool pbl_time_is_weekend ( enum pbl_weekday  day)
inlinestatic

Check whether a day is on the weekend (Saturday or Sunday).

Parameters
dayDay of the week.
Returns
true for Saturday and Sunday.

References PBL_SATURDAY, and PBL_SUNDAY.

◆ pbl_time_minute_of_day_adjust()

int pbl_time_minute_of_day_adjust ( int  minute,
int  delta 
)

Add a delta to a minute of the day, wrapping around midnight.

Parameters
minuteMinute of the day, 0 to 1439.
deltaMinutes to add, at most one day in either direction.
Returns
Adjusted minute of the day, 0 to 1439.

◆ pbl_time_split_seconds()

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.

Parameters
secondsDuration in seconds.
[out]daysWhole days.
[out]hoursRemaining hours, 0 to 23.
[out]minutesRemaining minutes, 0 to 59.
[out]secsRemaining seconds, 0 to 59.