Created
December 3, 2019 17:43
-
-
Save Crocmagnon/cc6505f6ba30ca272fe62a1f6336bd14 to your computer and use it in GitHub Desktop.
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
| WEEKDAYS = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] | |
| def day_of_week_offset(day, offset): | |
| return WEEKDAYS[(WEEKDAYS.index(day) + offset) % 7] | |
| def main(): | |
| assert day_of_week_offset("Monday", 0) == "Monday", "Same day" | |
| assert day_of_week_offset("Monday", 1) == "Tuesday", "Next day same week" | |
| assert day_of_week_offset("Tuesday", 3) == "Friday", "Several days later same week" | |
| assert day_of_week_offset("Friday", 3) == "Monday", "Week change" | |
| assert day_of_week_offset("Friday", 15) == "Saturday", "Multiple weeks change" | |
| assert day_of_week_offset("Friday", -1) == "Thursday", "Previous day, same week" | |
| assert day_of_week_offset("Friday", -2) == "Wednesday", "Several days in the past, same week" | |
| assert day_of_week_offset("Wednesday", -5) == "Friday", "Previous week" | |
| assert day_of_week_offset("Wednesday", -15) == "Tuesday", "Several weeks in the past" | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment