Skip to content

Instantly share code, notes, and snippets.

@yeiichi
Created January 14, 2025 06:41
Show Gist options
  • Save yeiichi/cff8ef41a4a054f16a91e423616611b3 to your computer and use it in GitHub Desktop.
Save yeiichi/cff8ef41a4a054f16a91e423616611b3 to your computer and use it in GitHub Desktop.
Return this or next Monday.
#!/usr/bin/env python3
from datetime import date, timedelta
def find_next_monday(yyyymmdd):
"""Return this or next Monday.
"""
date_iso = date.fromisoformat(yyyymmdd)
day_o_wk = date_iso.isocalendar().weekday # Mon: 1, ... Sun: 7
dy_delta = 8 - day_o_wk
next_mon = date_iso + timedelta(days=dy_delta)
return date_iso if day_o_wk == 1 else next_mon
if __name__ == '__main__':
mon = find_next_monday(input('Date? (ISO format) >> ')).strftime('%a, %Y-%m-%d')
print(f'Next(or this) Monday is {mon}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment