Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add gmtime() to time module #1663

Open
CedarGroveStudios opened this issue Mar 18, 2019 · 3 comments
Open

add gmtime() to time module #1663

CedarGroveStudios opened this issue Mar 18, 2019 · 3 comments
Labels
cpython api modules from cpython
Milestone

Comments

@CedarGroveStudios
Copy link

CedarGroveStudios commented Mar 18, 2019

Add gmtime() to support foundational timekeeping in UTC to permit conversion to localtime() or when calculating the UTC offset for a local timezone. See discussion: adafruit/Adafruit_CircuitPython_PyPortal/issues #16

@jerryneedell
Copy link
Collaborator

jerryneedell commented Oct 11, 2019

I was looking into this and want to make sure I understand what is needed.
As far as I can tell, the time module only knows about "local time" it has no concept of Time Zone.

However -- when we have an internet connection and us the adafruit_ntp library to set the time, it sets it to GMT.

Do we need to add Time zone awareness and then return localtime or gmtime as requested?

I am thinking that was is now referred to as localtime should really be gmtime and if local time requested, use the Time Zone setting to offset it..

edited to add..
or perhaps it is better to keep localtime as it is and just create gmtime based on the Time Zone (default to GMT) -- the NTP library would have to be modified to set the loacal time based on the Time Zone as well.

Is that what you have in mind? Or have I missed the point entirely...

@CedarGroveStudios
Copy link
Author

I think you've got it. The primary objective is to be able to determine local time accurately based on gmtime when it's available. The nice-to-have would be to calculate gmtime from local time when an actively-updated gmtime isn't available.

Since the flag is available, calculating and including the DST offset would be frosting on the cake.
>>> time.localtime() Out[2]: time.struct_time(tm_year=2019, tm_mon=3, tm_mday=18, tm_hour=0, tm_min=3, tm_sec=26, tm_wday=0, tm_yday=77, tm_isdst=1)

@calcut
Copy link

calcut commented Feb 15, 2022

Slightly confused - are we saying that currently time.localtime(posix_seconds) always returns in UTC?
i.e. does it do the same as time.gmtime(posix_seconds) would do if it was available?

if not, how does it figure out what local time should be? it doesn't seem to automagically pick up the timezone from secrets.py

(my timezone is currently == UTC, which makes it harder to spot potential issues!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cpython api modules from cpython
Projects
None yet
Development

No branches or pull requests

5 participants