tzname = os.popen("systemsetup -gettimezone").read().replace("Time Zone: ", "").strip()
if not tzname or tzname not in pytz.all_timezones_set:
# link will be something like /usr/share/zoneinfo/America/Los_Angeles.
link = os.readlink("/etc/localtime")
tzname = link[link.rfind('/', 0, link.rfind('/'))+1:]
return pytz.timezone(tzname)
ok I analyzed the issue
tzname = os.popen( "systemsetup -gettimezone" ).read( ).replace( "Time Zone: ", "").strip() timezones_ set: zoneinfo/ America/ Los_Angeles. "/etc/localtime ") rfind(' /', 0, link.rfind( '/'))+1: ] tzname)
if not tzname or tzname not in pytz.all_
# link will be something like /usr/share/
link = os.readlink(
tzname = link[link.
return pytz.timezone(
The above code will run like this
tzname = os.popen( "systemsetup -gettimezone" ).read( ).replace( "Time Zone: ", "").strip()
This line won't work because you need admin access to get that tool: This you will get back:
You need administrator access to run this tool... exiting!
Then link = os.readlink( "/etc/localtime ")
Will give back
/usr/share/ zoneinfo/ America/ Argentina/ Buenos_ Aires
link[link. rfind(' /', 0, link.rfind( '/'))+1: ]
and above code will only return Argentina/ Buenos_ Aires
Looking at above code there are many pytz.all_ timezones_ set where this code will actually fail:
'America/ Indiana/ Indianapolis' , 'America/ Indiana/ Knox', 'America/ Indiana/ Marengo' , 'America/ Indiana/ Petersburg' , 'America/ Indiana/ Tell_City' , 'America/ Indiana/ Vevay', 'America/ Indiana/ Vincennes' , 'America/ Indiana/ Winamac'
'America/ Argentina/ Buenos_ Aires', 'America/ Argentina/ Catamarca' , 'America/ Argentina/ ComodRivadavia' , 'America/ Argentina/ Cordoba' , 'America/ Argentina/ Jujuy', 'America/ Argentina/ La_Rioja' , 'America/ Argentina/ Mendoza' , 'America/ Argentina/ Rio_Gallegos' , 'America/ Argentina/ Salta', 'America/ Argentina/ San_Juan' , 'America/ Argentina/ San_Luis' , 'America/ Argentina/ Tucuman' , 'America/ Argentina/ Ushuaia' ,