Skip to content

Commit

Permalink
Fix UTC time handeling, fixes #2195
Browse files Browse the repository at this point in the history
Using the solution suggested by Sascha Silbe [1].  TL;DR "All of the
UTC+X UTC-X timezones could be translated into entries in
/usr/share/zoneinfo/Etc. For example, "UTC-5" would be converted to
TZ=:Etc/GMT+5"

Simmilar to Quozl's patch [2].  Quozl explains his patch as "translating
from ISO 8601 to POSIX.1 format, by reversing the sign"

[1]: http://lists.sugarlabs.org/archive/sugar-devel/2011-March/030532.html
[2]: http://lists.sugarlabs.org/archive/sugar-devel/2011-March/030497.html
  • Loading branch information
samdroid-apps authored and godiard committed Nov 17, 2014
1 parent 6b83253 commit 4a4bc30
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions extensions/cpsection/datetime/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,28 @@ def print_timezone():
print get_timezone()


def fix_UTC_time_zone(timezone):
# Fixes the issue where the timezones are
# wrong when using UTC to set the time.
# This works by inverting the +/- and using
# the Etc/GMT... to be POSIX compliant.
if '+' in timezone:
new = timezone.replace('+', '-')
elif '-' in timezone:
new = timezone.replace('-', '+')
else:
new = 'UTC'
return 'Etc/' + new.replace('UTC', 'GMT')


def set_timezone(timezone):
"""Set the system timezone
timezone : e.g. 'America/Los_Angeles'
"""
timezones = read_all_timezones()
if timezone in timezones:
if timezone.startswith('UTC'):
timezone = fix_UTC_time_zone(timezone)
os.environ['TZ'] = timezone
settings = Gio.Settings('org.sugarlabs.date')
settings.set_string('timezone', timezone)
Expand Down

0 comments on commit 4a4bc30

Please sign in to comment.