For my clock, I want automatic handling of Daylight Saving Time. However, CircuitPython doesn't build in any distinction between local and UTC time, and fitting in the entire Python3 datetime module or an Olson time zone database is simply not going to happen. What can we do that is simple enough to fit, but can represent the reality of timezones where I live?
Stipulations:
- If the DST law changes, it's OK if I have to edit the code
- If I move, it's OK if I have to edit the code
- If I outlive the Unix time epoch, it's OK if I have to edit the code
- If none of those happen, the code should behave correctly indefinitely
POSIX systems define several kinds of time zone rules that apply the same rule every year. The type that describes the US Central Time Zone rule is the "M" rule, which has a month, week-of-month, and day-of-week for the change. Week "5" means the last week of the month, but it's not required.
I decided to implement "M"-rules, and modeled my code after the newlib C library implementation, without last-week support.
The "real" CircuitPython RTC has to be set to UTC time for this code to work.
Entry first conceived on 17 July 2020, 21:37 UTC, last modified on 18 July 2020, 13:56 UTC
Website Copyright © 2004-2024 Jeff Epler