From 2f26c172ed61ec4035c7a4667187ad0fd19e8dd7 Mon Sep 17 00:00:00 2001 From: Michael Mogenson Date: Tue, 14 Mar 2023 21:18:04 -0400 Subject: [PATCH] clock.py: constrain hour to 0 to 24 Use a modulo to constrain the displayed hour to 0 - 24 after applying the UTC offset. --- micropython/examples/cosmic_unicorn/clock.py | 2 +- micropython/examples/galactic_unicorn/clock.py | 2 +- micropython/examples/interstate75/75W/clock.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/micropython/examples/cosmic_unicorn/clock.py b/micropython/examples/cosmic_unicorn/clock.py index 2c51ed09..0ccfc1f5 100644 --- a/micropython/examples/cosmic_unicorn/clock.py +++ b/micropython/examples/cosmic_unicorn/clock.py @@ -180,7 +180,7 @@ def redraw_display_if_reqd(): year, month, day, wd, hour, minute, second, _ = rtc.datetime() if second != last_second: - hour += utc_offset + hour = (hour + utc_offset) % 24 time_through_day = (((hour * 60) + minute) * 60) + second percent_through_day = time_through_day / 86400 percent_to_midday = 1.0 - ((math.cos(percent_through_day * math.pi * 2) + 1) / 2) diff --git a/micropython/examples/galactic_unicorn/clock.py b/micropython/examples/galactic_unicorn/clock.py index b34f6da3..8e23be52 100644 --- a/micropython/examples/galactic_unicorn/clock.py +++ b/micropython/examples/galactic_unicorn/clock.py @@ -180,7 +180,7 @@ def redraw_display_if_reqd(): year, month, day, wd, hour, minute, second, _ = rtc.datetime() if second != last_second: - hour += utc_offset + hour = (hour + utc_offset) % 24 time_through_day = (((hour * 60) + minute) * 60) + second percent_through_day = time_through_day / 86400 percent_to_midday = 1.0 - ((math.cos(percent_through_day * math.pi * 2) + 1) / 2) diff --git a/micropython/examples/interstate75/75W/clock.py b/micropython/examples/interstate75/75W/clock.py index c95ca905..d3b5fd47 100644 --- a/micropython/examples/interstate75/75W/clock.py +++ b/micropython/examples/interstate75/75W/clock.py @@ -156,7 +156,7 @@ def redraw_display_if_reqd(): year, month, day, wd, hour, minute, second, _ = rtc.datetime() if second != last_second: - hour += utc_offset + hour = (hour + utc_offset) % 24 time_through_day = (((hour * 60) + minute) * 60) + second percent_through_day = time_through_day / 86400 percent_to_midday = 1.0 - ((math.cos(percent_through_day * math.pi * 2) + 1) / 2)