Skip to content

Return UTC differential value from adafruit_pyportal.get_local_time() #16

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

Closed
CedarGroveStudios opened this issue Mar 18, 2019 · 10 comments

Comments

@CedarGroveStudios
Copy link

It would be very useful for calculating time-dependent values (such as sunrise and sunset times) if the adafruit_pyportal.get_local_time module also returned the UTC differential value for the local time zone.

@ladyada
Copy link
Member

ladyada commented Mar 18, 2019

that data is requested
https://github.com/adafruit/Adafruit_CircuitPython_PyPortal/blob/master/adafruit_pyportal.py#L86
but we don't do anything with it
https://github.com/adafruit/Adafruit_CircuitPython_PyPortal/blob/master/adafruit_pyportal.py#L555
i dont think the python time module can track UTC - so would that be some other time struct? like where would we keep track of it :)

@CedarGroveStudios
Copy link
Author

I believe that in Python3, the base time is UTC and localtime is derived from that. Does CircuitPython do it that way or is the foundational time the local time? If that's the case, then perhaps the offset could be derived from a json query and stored as an attribute in pyportal.py. (I'm way out of my league here.)

@ladyada
Copy link
Member

ladyada commented Mar 18, 2019

hmm - how would you ask Cpython for utc and local time?

@makermelissa
Copy link
Collaborator

Couldn't you just temporarily set your timezone to something like "Etc/UTC" to get UTC?

@CedarGroveStudios
Copy link
Author

CedarGroveStudios commented Mar 18, 2019

Here's how it works in the Python3 REPL:

Jupyter QtConsole 4.3.1
Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 17:26:49) [MSC v.1900 32 bit (Intel)]
Type 'copyright', 'credits' or 'license' for more information
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.

>>> import time

>>> 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)

>>> time.gmtime()
Out[3]: time.struct_time(tm_year=2019, tm_mon=3, tm_mday=18, tm_hour=7, tm_min=3, tm_sec=32, tm_wday=0, tm_yday=77, tm_isdst=0)

>>> time.gmtime()[3] - time.localtime()[3]
Out[4]: 7


@CedarGroveStudios
Copy link
Author

^^ I'll try that for now. Thanks @makermelissa!

@ladyada
Copy link
Member

ladyada commented Mar 18, 2019

sounds like we should add gmtime() to time at some point, wanna open up an issue on circuitpython for that? then we would be able to have two times!

@CedarGroveStudios
Copy link
Author

I'll do that! I'll close this issue since I think we have a potential workaround with @makermelissa 's suggestion.

@ladyada
Copy link
Member

ladyada commented Mar 18, 2019

yay!

@CedarGroveStudios
Copy link
Author

CedarGroveStudios commented Mar 18, 2019

Done! adafruit/circuitpython #1663

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

No branches or pull requests

3 participants