Skip to content

Instantly share code, notes, and snippets.

@righ
Created May 4, 2016 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save righ/61c83d856323b73ee07a26ec2f40f210 to your computer and use it in GitHub Desktop.
Save righ/61c83d856323b73ee07a26ec2f40f210 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# coding: utf-8
import sys
def format_timezones(timezones, descriptor=sys.stdout):
_tz = ()
for tz in sorted(t.split('/') for t in timezones):
for indent, region in enumerate(tz):
if len(_tz) > indent and _tz[indent] == tz[indent]:
continue
if len(tz) - 1 == indent:
descriptor.write('{}- {}\n'.format(' ' * indent, '/'.join(tz)))
else:
descriptor.write('{}+ {}\n'.format(' ' * indent, region))
_tz = tz
if __name__ == '__main__':
import pytz
format_timezones(pytz.all_timezones)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment