Skip to content

Instantly share code, notes, and snippets.

@quandyfactory
Last active December 16, 2015 10:39
Show Gist options
  • Save quandyfactory/5421431 to your computer and use it in GitHub Desktop.
Save quandyfactory/5421431 to your computer and use it in GitHub Desktop.
It's 5 O'Clock Somewhere: This script tells you the nearest time zone in which it's after 5 o'clock PM.
#!/usr/bin/env python
"""This script tells you the nearest time zone in which it's after 5 o'clock PM."""
import datetime
def get_beer_timezone():
now = datetime.datetime.today()
print("The curent time is %s." % (str(now)[11:-7]))
if now.hour >= 17:
print("It's after 5 o'clock right here. Crack open that beer!")
else:
utc = datetime.datetime.utcnow()
offset = (utc - now)
timezone = offset.seconds/60/60*-1
print("Your time zone is UTC%s%s." % ("" if timezone < 0 else "+", timezone))
hours_left = 17 - now.hour
if timezone + hours_left <=12:
beerzone = timezone + hours_left
else:
beerzone = -13 + (timezone + hours_left - 12)
print("It's 5 o'clock in timezone UTC%s%s. Go there and have a beer." % (
"" if beerzone < 0 else "+",
beerzone
)
)
if __name__ == '__main__':
get_beer_timezone()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment