Time now auto-updates with DST
This commit is contained in:
@@ -83,6 +83,39 @@ uint8_t is_leap(uint16_t y)
|
||||
return !(y%4) && ((y%100) || !(y%400));
|
||||
}
|
||||
|
||||
uint8_t is_dst(watch_date_time date_time) {
|
||||
uint8_t weekday_first_of_month;
|
||||
watch_date_time dst_start_time;
|
||||
watch_date_time dst_end_time;
|
||||
uint32_t unix_dst_start_time;
|
||||
uint32_t unix_dst_end_time;
|
||||
uint32_t unix_curr_time;
|
||||
|
||||
dst_start_time.unit.month = 3;
|
||||
dst_start_time.unit.hour = 2;
|
||||
dst_start_time.unit.minute = 0;
|
||||
dst_start_time.unit.second = 0;
|
||||
weekday_first_of_month = watch_utility_get_iso8601_weekday_number(date_time.unit.year, dst_start_time.unit.month, 1);
|
||||
dst_start_time.unit.day = 15 - weekday_first_of_month;
|
||||
unix_dst_start_time = watch_utility_date_time_to_unix_time(dst_start_time, 0);
|
||||
|
||||
dst_end_time.unit.month = 11;
|
||||
dst_end_time.unit.hour = 2;
|
||||
dst_end_time.unit.minute = 0;
|
||||
dst_end_time.unit.second = 0;
|
||||
weekday_first_of_month = watch_utility_get_iso8601_weekday_number(date_time.unit.year, dst_end_time.unit.month, 1);
|
||||
dst_end_time.unit.day = 15 - weekday_first_of_month;
|
||||
unix_dst_end_time = watch_utility_date_time_to_unix_time(dst_end_time, 0);
|
||||
|
||||
date_time.unit.second = 0;
|
||||
unix_curr_time = watch_utility_date_time_to_unix_time(date_time, 0);
|
||||
|
||||
if (unix_curr_time == unix_dst_start_time) return DST_STARTED;
|
||||
if (unix_curr_time == unix_dst_end_time) return DST_ENDING;
|
||||
if (unix_curr_time > unix_dst_end_time || unix_curr_time < unix_dst_start_time) return DST_ENDED;
|
||||
return DST_OCCURRING;
|
||||
}
|
||||
|
||||
uint16_t watch_utility_days_since_new_year(uint16_t year, uint8_t month, uint8_t day) {
|
||||
uint16_t DAYS_SO_FAR[] = {
|
||||
0, // Jan
|
||||
|
||||
@@ -45,6 +45,13 @@ typedef struct {
|
||||
uint32_t days; // 0-4294967295
|
||||
} watch_duration_t;
|
||||
|
||||
typedef enum {
|
||||
DST_STARTED,
|
||||
DST_OCCURRING,
|
||||
DST_ENDING,
|
||||
DST_ENDED
|
||||
} dst_t;
|
||||
|
||||
/** @brief Returns a two-letter weekday for the given timestamp, suitable for display
|
||||
* in positions 0-1 of the watch face
|
||||
* @param date_time The watch_date_time whose weekday you want.
|
||||
@@ -78,6 +85,12 @@ uint16_t watch_utility_days_since_new_year(uint16_t year, uint8_t month, uint8_t
|
||||
*/
|
||||
uint8_t is_leap(uint16_t year);
|
||||
|
||||
/** @brief Returns off of dst_t based off if DST is occurring, srted, ended, or none of those.
|
||||
* @param date_time The watch_date_time that you wish to convert.
|
||||
* @return DST_OCCURRING, DST_HAPPENING, DST_ENDING, DST_ENDED
|
||||
*/
|
||||
uint8_t is_dst(watch_date_time date_time);
|
||||
|
||||
/** @brief Returns the UNIX time (seconds since 1970) for a given date/time in UTC.
|
||||
* @param date_time The watch_date_time that you wish to convert.
|
||||
* @param year The year of the date you wish to convert.
|
||||
|
||||
Reference in New Issue
Block a user