Created
January 14, 2025 06:41
-
-
Save yeiichi/cff8ef41a4a054f16a91e423616611b3 to your computer and use it in GitHub Desktop.
Return this or next Monday.
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
#!/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