Skip to content

Instantly share code, notes, and snippets.

@DamnWidget
Last active December 15, 2015 09:49
Show Gist options
  • Save DamnWidget/5241004 to your computer and use it in GitHub Desktop.
Save DamnWidget/5241004 to your computer and use it in GitHub Desktop.
Calculate the next wednesday/saturday date
from datetime import datetime, timedelta
def get_next_day(d, day=2):
return d + timedelta((day - d.weekday()) % 7)
def get_next_lotto_day(d):
next_wednesday = get_next_day(d)
next_saturday = get_next_day(d, 5)
if (next_wednesday - d).days == 0:
# today is wednesday
return next_saturday if datetime.now().hour >= 20 else d
elif (next_wednesday - d).days == 4:
# today is saturday
return next_wednesday if datetime.now().hour >= 20 else next_saturday
elif (next_wednesday - d).days > 4:
return next_saturday
return next_wednesday
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment