Minimal Time-Zone Handling for CircuitPython

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:

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-2018 Jeff Epler