Return offset in the same format as Unix

This commit is contained in:
twangboy 2018-05-23 15:00:09 -06:00
parent 5656183c5e
commit 73e033f555
No known key found for this signature in database
GPG key ID: 93FF3BDEB278C9EB

View file

@ -226,11 +226,10 @@ def get_offset():
'''
# http://craigglennie.com/programming/python/2013/07/21/working-with-timezones-using-Python-and-pytz-localize-vs-normalize/
tz_object = pytz.timezone(get_zone())
utc_time = pytz.utc.localize(datetime.today())
utc_time = pytz.utc.localize(datetime.utcnow())
loc_time = utc_time.astimezone(tz_object)
norm_time = tz_object.normalize(loc_time)
time_zone = norm_time.astimezone(tz_object)
return time_zone.utcoffset().total_seconds() / 3600
return norm_time.strftime('%z')
def get_zonecode():
@ -247,7 +246,7 @@ def get_zonecode():
salt '*' timezone.get_zonecode
'''
tz_object = pytz.timezone(get_zone())
loc_time = tz_object.localize(datetime.today())
loc_time = tz_object.localize(datetime.utcnow())
return loc_time.tzname()