adafruit / Adafruit_CircuitPython_DS3231

Adafruit CircuitPython drivers for the DS3231 realtime clock.
MIT License
21 stars 19 forks source link

Incorrectly setting Day of Year and DST #40

Closed DCMattyG closed 2 years ago

DCMattyG commented 2 years ago

I've been working with the DS3231 library and I noticed that it seems to not properly set the Day of Year or DST.

Here is some example code and output:

localtime() time.struct_time(tm_year=2022, tm_mon=1, tm_mday=1, tm_hour=2, tm_min=56, tm_sec=29, tm_wday=5, tm_yday=1, tm_isdst=0) CLOCK.datetime = localtime() CLOCK.datetime time.struct_time(tm_year=2022, tm_mon=1, tm_mday=1, tm_hour=2, tm_min=56, tm_sec=36, tm_wday=5, tm_yday=-1, tm_isdst=-1)

CLOCK is my DS3231 object created from the Adafruit library (per the example docs). Notice that even though the localtime() is passing in tm_yday=1 and tm_isdst=0, those are both getting read as -1 from the DS3231 after setting.

Please let me know if you need any further details. Using Python 3.9 and latest library available from PyPi.

tekktrik commented 2 years ago

Hey @DCMattyG, currently those fields are not supported by CircuitPython. You know you can manually set the DST field, but Day of Year and DST are never set by methods like localtime(). Hope that helps!

DCMattyG commented 2 years ago

Python's time.localtime() does indeed return a 'Day of Year' and DST value, it's the same as time.gmtime() except it's converted to local time. In my use case, I would like my DS3231 to be in local time as opposed to something like UTC, so time.localtime() serves that function well.

That said, you did answer my question that those fields aren't supported by CiruitPython, so I can work on an alternative method for the time being. Appreciate the feedback.