Last active
December 15, 2015 09:49
-
-
Save DamnWidget/5241004 to your computer and use it in GitHub Desktop.
Calculate the next wednesday/saturday date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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