From a733b8cf505b079f2c86b93ee1cdb500ff74d23c Mon Sep 17 00:00:00 2001 From: cos Date: Sun, 17 Apr 2022 06:01:04 -0400 Subject: Handle DST for the extra timezones displayed Prior to this commit, the watchface needed to be recompiled and reinstalled a few times a year. Which was a bit of a hassle. Unreliable on the actual days when UTC offset changes, since no attempts are made at hitting the exact hour. That's good enough for me. --- LICENSE | 2 +- Makefile | 2 +- manifest.xml | 2 +- source/MazarineView.mc | 37 +++++++++++++++++++++++++++++++++---- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/LICENSE b/LICENSE index 37c7f6a..a515fbd 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (C) 2019 cy384, 2020 cos +Copyright (C) 2019 cy384, 2020-2022 cos All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/Makefile b/Makefile index 852367d..51d444e 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ DEVICE=vivoactive3 SDK=3.1.7 -VERSION="0.0.2" +VERSION="0.0.3" OUTPUT=bin/mazarine_$(VERSION).prg MONKEY_SDK=~/CONNECTIQ CONNIQ=$(MONKEY_SDK)/bin/connectiq diff --git a/manifest.xml b/manifest.xml index 5638436..abf2ea2 100644 --- a/manifest.xml +++ b/manifest.xml @@ -1,5 +1,5 @@ - + diff --git a/source/MazarineView.mc b/source/MazarineView.mc index d0c5228..725b5d9 100644 --- a/source/MazarineView.mc +++ b/source/MazarineView.mc @@ -1,6 +1,6 @@ // Mazarine // -// Copyright (C) 2019 cy384, 2020 cos +// Copyright (C) 2019 cy384, 2020-2022 cos // All rights reserved. // // This software may be modified and distributed under the terms @@ -133,12 +133,41 @@ class MazarineView extends WatchUi.WatchFace { } function draw_timezones(dc) { + var today = Gregorian.info(Time.now(), Time.FORMAT_SHORT); + var weekday; + weekday = today.day_of_week - 1; + + var past_first_sunday = (today.day - weekday) > 0; + var past_second_sunday = (today.day > 7) && (today.day - weekday > 7); + draw_utc_offset(dc); draw_timezone(dc, 1, "HK", 8); // draw_timezone(dc, 3, "ACDT", 10.5); - draw_timezone(dc, 2, "NSW", 11); - draw_timezone(dc, 3, "NY", -4); - draw_timezone(dc, 4, "CA", -7); + + // https://en.wikipedia.org/wiki/Time_in_Australia + // "first Sunday in October first Sunday in April" + if ((today.month > 4 && today.month < 10) || + (today.month == 4 && past_first_sunday ) || + (today.month == 10 && !past_first_sunday )) + { + draw_timezone(dc, 2, "NSW", 10); + } else { + draw_timezone(dc, 2, "NSW", 11); + } + + // https://en.wikipedia.org/wiki/Daylight_saving_time_in_the_United_States + // "In the U.S., daylight saving time starts on the second Sunday in + // March and ends on the first Sunday in November" + if ((today.month > 3 && today.month < 11) || + (today.month == 3 && past_second_sunday ) || + (today.month == 11 && !past_first_sunday )) + { + draw_timezone(dc, 3, "NY", -4); + draw_timezone(dc, 4, "CA", -7); + } else { + draw_timezone(dc, 3, "NY", -5); + draw_timezone(dc, 4, "CA", -8); + } } function draw_utc_offset(dc) { -- cgit v1.2.3