tingbot / tingbot-os

📦 The Tingbot operating system
http://tingbot.com
37 stars 14 forks source link

Add ability for user to change timezone #23

Open joerick opened 8 years ago

joerick commented 8 years ago

Should probably work similarly to the Wifi setup (and hostname #22 perhaps!), configuration on the SD from Tide.

jessea3 commented 7 years ago

As a workaround in the mean time, you can set the timezone within the particular app. You can store the timezone in any python-legal format in your app.settings file. The example shows a hardcoded one for the US/Eastern time zone.


import time
import os

# setup code here

#os.environ['TZ'] = 'EST+05EDT,M4.1.0,M10.5.0'
os.environ['TZ'] = tingbot.app.settings['timezone']
time.tzset()
bsheff commented 7 years ago

your example:

os.environ['TZ'] = 'EST+05EDT,M4.1.0,M10.5.0'

os.environ['TZ'] = tingbot.app.settings['timezone'] time.tzset() causes diagnostic: "line 68, in getitem return self.dct[key] keyerror: 'timezone' " on the other hand,

current_time = time.strftime("%A\n %Y-%m-%d %H:%M:%S %Z")

simulator produced: "Sunday 2017-01-22 22:55:10 Eastern Standard Time" (too bad I couldnt Mark/Copy/paste) actual Tingbot produced: Monday 2017 -01-23 03:28:31 UTC" why not EST? why cant I set the TIMEZONE in Tingbot?, (or better yet you could get it from local server on Bootup)

jessea3 commented 7 years ago

Did you set timezone in app.settings? I had placed the value there to generalize the code, but it could be hardcoded as well.

Python is returning a time relative to the machine you are running it on. In the case of the emulator, it is pulling the TZ from your computer, but on the Tingbot it is either undefined (which defaults to UTC) or set to UTC explicitly - I haven't dug deep enough to check.

If you want to do a quick check, try the following:

import time
import os

# setup code here
print time.strftime("%A\n %Y-%m-%d %H:%M:%S %Z")
os.environ['TZ'] = 'EST+05EDT,M4.1.0,M10.5.0'
time.tzset()
print time.strftime("%A\n %Y-%m-%d %H:%M:%S %Z")

see the python docs for more information...

Ideally, the timezone value will be written to the SD card at the same time as the wireless information - I need to dig into the source and see what is being done....