|
PebbleOS v4.47.0-512-g5285d4236
|
Wall clock time, timezone and user-facing time formatting. More...
Macros | |
| #define | TIME_STRING_REQUIRED_LENGTH 20 |
| Buffer size for common strings like "Wednesday" or "30 minutes ago". | |
| #define | TIME_STRING_TIME_LENGTH 10 |
| Buffer size for a time, e.g. | |
| #define | TIME_STRING_DATE_LENGTH 10 |
| Buffer size for a day and month, e.g. | |
| #define | TIME_STRING_DAY_DATE_LENGTH 3 |
| Buffer size for a day of the month, e.g. | |
Functions | |
| void | clock_restore_time (void) |
| Restore the wall clock from the RTC. | |
| void | clock_init (void) |
| Initialize the clock service. | |
| void | clock_hourly_chime_arm (void) |
| Arm the hourly chime. | |
| void | clock_get_time_tm (struct pbl_tm *time_tm) |
| Get the current local time from the RTC. | |
| size_t | clock_format_time (char *buffer, uint8_t size, int16_t hours, int16_t minutes, bool add_space) |
| Format a time of day according to the user's 12h/24h preference. | |
| size_t | clock_copy_time_string_timestamp (char *buffer, uint8_t size, time_t timestamp) |
| Same as clock_copy_time_string(), for a given timestamp. | |
| size_t | clock_get_time_number (char *buffer, size_t buffer_size, time_t timestamp) |
| Format a time as "7:30" or "15:00" depending on the user's 12h/24h preference. | |
| size_t | clock_get_time_word (char *buffer, size_t buffer_size, time_t timestamp) |
| Get the AM/PM designator of a time. | |
| void | clock_get_event_relative_time_string (char *number_buffer, int number_buffer_size, char *word_buffer, int word_buffer_size, time_t timestamp, uint16_t duration, time_t current_day, bool all_day) |
| Get the relative time string of an event, split in a number and a word. | |
| void | clock_set_24h_style (bool is_24h_style) |
| Set the user's time display style. | |
| bool | clock_timezone_source_is_manual (void) |
| Check whether the timezone is selected manually. | |
| void | clock_set_manual_timezone_source (bool manual) |
| Set the timezone source. | |
| bool | clock_time_source_is_manual (void) |
| Check whether the time is set manually. | |
| void | clock_set_manual_time_source (bool manual) |
| Set the time source. | |
| void | clock_request_time_from_phone (void) |
| Ask the phone to send its current time. | |
| void | clock_get_timezone_region (char *region_name, const size_t buffer_size) |
| Get the name of the current timezone region, e.g. | |
| int16_t | clock_get_timezone_region_id (void) |
| Get the current timezone region. | |
| void | clock_set_timezone_by_region_id (uint16_t region_id) |
| Switch to a timezone region and fire a time change event. | |
| void | clock_set_time (time_t utc_time) |
| Set the current UTC time and fire a time change event. | |
| void | clock_timezone_clear (void) |
| Forget the timezone, as part of a factory reset. | |
| const char * | time_t_to_string (char *buffer, time_t t) |
| Format a time as local time. | |
| void | clock_get_friendly_date (char *buffer, int buf_size, time_t timestamp) |
| Get a friendly date for a timestamp. | |
| void | clock_get_since_time (char *buffer, int buf_size, time_t timestamp) |
| Get a friendly time elapsed since a timestamp, e.g. | |
| void | clock_get_until_time (char *buffer, int buf_size, time_t timestamp, int max_relative_hrs) |
| Get a friendly time relative to a timestamp, e.g. | |
| void | clock_get_until_time_without_fulltime (char *buffer, int buf_size, time_t timestamp, int max_relative_hrs) |
| clock_get_until_time_capitalized() that never writes the time of day. | |
| size_t | clock_get_date (char *buffer, int buf_size, time_t timestamp) |
| Get the date in MM/DD format. | |
| size_t | clock_get_date_tm (char *buffer, int buf_size, const struct pbl_tm *time_tm) |
| Same as clock_get_date(), from a broken-down time. | |
| size_t | clock_get_day_date (char *buffer, int buf_size, time_t timestamp) |
| Get the day of the month in DD format. | |
| size_t | clock_get_month_named_date (char *buffer, size_t buffer_size, time_t timestamp) |
| Get the date as month name and day, e.g. | |
| size_t | clock_get_month_named_abbrev_date (char *buffer, size_t buffer_size, time_t timestamp) |
| Get the date as abbreviated month name and day, e.g. | |
| void | clock_get_until_time_capitalized (char *buffer, int buf_size, time_t timestamp, int max_relative_hrs) |
| Capitalized clock_get_until_time(), e.g. | |
| const char * | clock_get_relative_daypart_string (time_t current_timestamp, uint32_t hours_in_the_future) |
| Get a daypart phrase for a time in the future, e.g. | |
| void | clock_hour_and_minute_add (int *hour, int *minute, int delta_minutes) |
| Add minutes to a wall clock time, wrapping around 24 hours. | |
Wall clock time, timezone and user-facing time formatting.
Keeps the RTC time and timezone, handles the time endpoint messages from the phone, tracks DST transitions and formats times and dates according to the user's 12h/24h preference and language. Entities shared with the app SDK are documented in the SDK's Wall Time group.
| #define TIME_STRING_DATE_LENGTH 10 |
Buffer size for a day and month, e.g.
"04/27".
| #define TIME_STRING_DAY_DATE_LENGTH 3 |
Buffer size for a day of the month, e.g.
"27".
| #define TIME_STRING_REQUIRED_LENGTH 20 |
Buffer size for common strings like "Wednesday" or "30 minutes ago".
| #define TIME_STRING_TIME_LENGTH 10 |
Buffer size for a time, e.g.
"14:20".
| size_t clock_copy_time_string_timestamp | ( | char * | buffer, |
| uint8_t | size, | ||
| time_t | timestamp | ||
| ) |
Same as clock_copy_time_string(), for a given timestamp.
| [out] | buffer | Output buffer. |
| size | Size of buffer. | |
| timestamp | Time to format. |
| size_t clock_format_time | ( | char * | buffer, |
| uint8_t | size, | ||
| int16_t | hours, | ||
| int16_t | minutes, | ||
| bool | add_space | ||
| ) |
Format a time of day according to the user's 12h/24h preference.
In 12h style, "AM" or "PM" is appended.
| [out] | buffer | Output buffer. |
| size | Size of buffer. | |
| hours | Hour, 0-23. | |
| minutes | Minute, 0-59. | |
| add_space | Whether to add a space between the time and AM/PM. |
buffer is NULL or size is 0. | size_t clock_get_date | ( | char * | buffer, |
| int | buf_size, | ||
| time_t | timestamp | ||
| ) |
Get the date in MM/DD format.
| [out] | buffer | Output buffer, at least TIME_STRING_DATE_LENGTH bytes. |
| buf_size | Size of buffer. | |
| timestamp | Time to format. |
| size_t clock_get_date_tm | ( | char * | buffer, |
| int | buf_size, | ||
| const struct pbl_tm * | time_tm | ||
| ) |
Same as clock_get_date(), from a broken-down time.
Avoids a pbl_localtime_r() round trip in tick handlers, which already get a struct pbl_tm.
| [out] | buffer | Output buffer, at least TIME_STRING_DATE_LENGTH bytes. |
| buf_size | Size of buffer. | |
| time_tm | Local time to format. |
| size_t clock_get_day_date | ( | char * | buffer, |
| int | buf_size, | ||
| time_t | timestamp | ||
| ) |
Get the day of the month in DD format.
| [out] | buffer | Output buffer, at least TIME_STRING_DAY_DATE_LENGTH bytes. |
| buf_size | Size of buffer. | |
| timestamp | Time to format. |
| void clock_get_event_relative_time_string | ( | char * | number_buffer, |
| int | number_buffer_size, | ||
| char * | word_buffer, | ||
| int | word_buffer_size, | ||
| time_t | timestamp, | ||
| uint16_t | duration, | ||
| time_t | current_day, | ||
| bool | all_day | ||
| ) |
Get the relative time string of an event, split in a number and a word.
E.g. "10" and " MIN. TO", so they can be rendered in different fonts. Close to the event, the word is "Now" and the number empty; further away, the event time is used. All-day events and middle days of multi-day events give "Today" or "All day".
| [out] | number_buffer | Output buffer for the number. |
| number_buffer_size | Size of number_buffer. | |
| [out] | word_buffer | Output buffer for the word. |
| word_buffer_size | Size of word_buffer. | |
| timestamp | Event start time. | |
| duration | Event duration, in minutes. | |
| current_day | Midnight of the day being displayed. | |
| all_day | Whether the event lasts all day. |
| void clock_get_friendly_date | ( | char * | buffer, |
| int | buf_size, | ||
| time_t | timestamp | ||
| ) |
Get a friendly date for a timestamp.
"Today", "Yesterday" or "Tomorrow", the weekday name up to 5 days ahead, else e.g. "June 21".
| [out] | buffer | Output buffer. |
| buf_size | Size of buffer. | |
| timestamp | Time to describe. |
| size_t clock_get_month_named_abbrev_date | ( | char * | buffer, |
| size_t | buffer_size, | ||
| time_t | timestamp | ||
| ) |
Get the date as abbreviated month name and day, e.g.
"Jul 16".
| [out] | buffer | Output buffer. |
| buffer_size | Size of buffer. | |
| timestamp | Time to format. |
| size_t clock_get_month_named_date | ( | char * | buffer, |
| size_t | buffer_size, | ||
| time_t | timestamp | ||
| ) |
Get the date as month name and day, e.g.
"July 16".
| [out] | buffer | Output buffer. |
| buffer_size | Size of buffer. | |
| timestamp | Time to format. |
| const char * clock_get_relative_daypart_string | ( | time_t | current_timestamp, |
| uint32_t | hours_in_the_future | ||
| ) |
Get a daypart phrase for a time in the future, e.g.
"this evening".
Covers today and tomorrow, then a single phrase for the day after and a catch-all beyond. The phrase is a lower bound, as in "Powered 'til at least ...".
| current_timestamp | Current time. |
| hours_in_the_future | Hours after current_timestamp. |
| void clock_get_since_time | ( | char * | buffer, |
| int | buf_size, | ||
| time_t | timestamp | ||
| ) |
Get a friendly time elapsed since a timestamp, e.g.
"Now" or "5 minutes ago".
Future timestamps are treated as now. Beyond 24 hours, or on another day, the date and time are used.
| [out] | buffer | Output buffer. |
| buf_size | Size of buffer. | |
| timestamp | Time to describe. |
| size_t clock_get_time_number | ( | char * | buffer, |
| size_t | buffer_size, | ||
| time_t | timestamp | ||
| ) |
Format a time as "7:30" or "15:00" depending on the user's 12h/24h preference.
AM/PM is not included; see clock_get_time_word(). Leading whitespace is stripped.
| [out] | buffer | Output buffer. |
| buffer_size | Size of buffer. | |
| timestamp | Time to format. |
| void clock_get_time_tm | ( | struct pbl_tm * | time_tm | ) |
Get the current local time from the RTC.
| [out] | time_tm | Current local time. |
| size_t clock_get_time_word | ( | char * | buffer, |
| size_t | buffer_size, | ||
| time_t | timestamp | ||
| ) |
Get the AM/PM designator of a time.
Use with clock_get_time_number() to form a full time.
| [out] | buffer | Output buffer; set to an empty string in 24h style. |
| buffer_size | Size of buffer. | |
| timestamp | Time to format. |
| void clock_get_timezone_region | ( | char * | region_name, |
| const size_t | buffer_size | ||
| ) |
Get the name of the current timezone region, e.g.
"America/Chicago".
Writes "---" if no timezone is set, or the UTC offset (e.g. "UTC-4") if the region is unknown.
| [out] | region_name | Output buffer, at least TIMEZONE_NAME_LENGTH bytes. |
| buffer_size | Size of region_name. |
| int16_t clock_get_timezone_region_id | ( | void | ) |
Get the current timezone region.
| void clock_get_until_time | ( | char * | buffer, |
| int | buf_size, | ||
| time_t | timestamp, | ||
| int | max_relative_hrs | ||
| ) |
Get a friendly time relative to a timestamp, e.g.
"Now" or "In 5 hours".
Past timestamps give "... ago". Beyond max_relative_hrs hours, or on another day, the date and time are used.
| [out] | buffer | Output buffer. |
| buf_size | Size of buffer. | |
| timestamp | Time to describe. | |
| max_relative_hrs | Number of hours for which a relative time is used. |
| void clock_get_until_time_capitalized | ( | char * | buffer, |
| int | buf_size, | ||
| time_t | timestamp, | ||
| int | max_relative_hrs | ||
| ) |
Capitalized clock_get_until_time(), e.g.
"NOW" or "IN 5 H".
| [out] | buffer | Output buffer. |
| buf_size | Size of buffer. | |
| timestamp | Time to describe. | |
| max_relative_hrs | Number of hours for which a relative time is used. |
| void clock_get_until_time_without_fulltime | ( | char * | buffer, |
| int | buf_size, | ||
| time_t | timestamp, | ||
| int | max_relative_hrs | ||
| ) |
clock_get_until_time_capitalized() that never writes the time of day.
Where the full form would include a time, only the day is written (e.g. "Yesterday", "Monday").
| [out] | buffer | Output buffer. |
| buf_size | Size of buffer. | |
| timestamp | Time to describe. | |
| max_relative_hrs | Number of hours for which a relative time is used. |
| void clock_hour_and_minute_add | ( | int * | hour, |
| int * | minute, | ||
| int | delta_minutes | ||
| ) |
Add minutes to a wall clock time, wrapping around 24 hours.
| [in,out] | hour | Hour, 0-23. |
| [in,out] | minute | Minute, 0-59. |
| delta_minutes | Minutes to add, may be negative. |
| void clock_hourly_chime_arm | ( | void | ) |
Arm the hourly chime.
Call once the services it uses (system resources, alerts preferences, vibe pattern service) are initialized.
| void clock_init | ( | void | ) |
Initialize the clock service.
Loads the timezone, starts writing the wall clock to the RTC periodically and starts the per-minute DST watch.
| void clock_request_time_from_phone | ( | void | ) |
Ask the phone to send its current time.
The phone answers with a set UTC and timezone message (sub-command 0x03). Does nothing if there is no system session.
| void clock_restore_time | ( | void | ) |
Restore the wall clock from the RTC.
Called once, early during startup, before anything reads the time. An RTC that lost its time is moved forward to the minimum valid time.
| void clock_set_24h_style | ( | bool | is_24h_style | ) |
Set the user's time display style.
| is_24h_style | true for 24h style, false for 12h style. |
| void clock_set_manual_time_source | ( | bool | manual | ) |
Set the time source.
| manual | true to set the time on the watch, false to use the phone's time. |
| void clock_set_manual_timezone_source | ( | bool | manual | ) |
Set the timezone source.
| manual | true to use a timezone selected in settings, false to use the phone's timezone. |
| void clock_set_time | ( | time_t | utc_time | ) |
Set the current UTC time and fire a time change event.
| utc_time | New UTC time. |
| void clock_set_timezone_by_region_id | ( | uint16_t | region_id | ) |
Switch to a timezone region and fire a time change event.
| region_id | Index of the timezone in the timezone database. |
| bool clock_time_source_is_manual | ( | void | ) |
Check whether the time is set manually.
With a manual source the user sets the time in settings; otherwise the phone sets it.
| void clock_timezone_clear | ( | void | ) |
Forget the timezone, as part of a factory reset.
| bool clock_timezone_source_is_manual | ( | void | ) |
Check whether the timezone is selected manually.
With a manual source the user selects the timezone in settings; otherwise the phone sets it.
| const char * time_t_to_string | ( | char * | buffer, |
| time_t | t | ||
| ) |
Format a time as local time.
| [out] | buffer | Buffer of at least TIME_STRING_BUFFER_SIZE bytes. |
| t | Time to format. |
buffer.