Skip to content

Instantly share code, notes, and snippets.

@Vovvka
Last active February 13, 2024 01:03
Show Gist options
  • Save Vovvka/41090e38a77685935f4f0b9359e020fe to your computer and use it in GitHub Desktop.
Save Vovvka/41090e38a77685935f4f0b9359e020fe to your computer and use it in GitHub Desktop.
Date for Sites with Country in name or w/o for pytz
timezone_mapping = {
'argentina': 'America/Argentina/Buenos_Aires',
'pst': 'America/Los_Angeles',
'pdt': 'America/Los_Angeles',
'pst/pdt': 'America/Los_Angeles',
'PST': 'America/Los_Angeles',
'PST/PDT': 'America/Los_Angeles',
'CT(US&Canada)': 'US/Central',
'Central Time(US)': 'US/Central',
'ET(US&Canada)': 'US/Eastern',
'CET': 'Europe/Berlin',
'CET/CEST': 'Europe/Berlin',
'cet/cest': 'Europe/Berlin',
'cet': 'Europe/Berlin',
'chile': 'America/Santiago',
'bst/gmt': 'Europe/London',
'bst': 'Europe/London',
'BST': 'Europe/London',
'GMT': 'Europe/London',
'UTC': 'Etc/UTC',
'BST/GMT': 'Europe/London',
'colombia': 'America/Bogota',
'Central Time(US)': 'US/Central',
'AEST': 'Australia/Sydney',
'aest': 'Australia/Sydney',
'NZDT': 'NZ',
'JST': 'Japan',
'Brazil': 'America/Noronha',
'Brussels': 'Europe/Brussels',
'Dublin': 'Europe/Dublin',
'France': 'Europe/Paris',
'India': 'Asia/Kolkata',
'Argentina': 'America/Argentina/Buenos_Aires',
'Colombia': 'America/Bogota',
'Mexico': 'America/Mexico_City',
'Spain': 'Europe/Madrid',
'China': 'Asia/Shanghai',
'Greece': 'Europe/Athens',
'Portugal': 'Europe/Lisbon',
'Taiwan': 'Asia/Taipei',
'UK': 'Europe/London',
#add
}
if start_timezone.lower() == 'local time':
# Split the collection name and look for Country in site name
for zone in collection.split():
pytz_timezone = timezone_mapping.get(zone)
if pytz_timezone:
print(f"mapped timezone: {pytz_timezone}")
return pytz_timezone
else:
# time zone direct search
pytz_timezone = timezone_mapping.get(start_timezone.strip())
if pytz_timezone:
print(f"Found timezone: {pytz_timezone}")
return pytz_timezone
else:
raise ValueError(f"No timezone found for '{start_timezone}'")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment