Created
December 2, 2019 23:33
-
-
Save djsmith42/6caf648b89ec6157103a10346474f932 to your computer and use it in GitHub Desktop.
This file contains 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
# -*- coding: UTF-8 -*- | |
DAYS_OF_THE_WEEK = { | |
"en_US": {"Sunday": 0, "Monday": 1, "Tuesday": 2, "Wednesday": 3, "Thursday": 4, "Friday": 5, "Saturday": 6}, | |
"es_ES": {"Domingo": 0, "Lunes": 1, "Martes": 2, "Miercoles": 3, "Jueves": 4, "Viernes": 5, "Sabado": 6}, | |
"ja_JP": {"日曜日": 0, "月曜日": 1, "火曜日": 2, "水曜日": 3, "木曜日": 4, "金曜日": 5, "土曜日": 6}, | |
} | |
REVERSE_DAYS_OF_THE_WEEK = dict((locale, dict(map(reversed, days.items()))) | |
for locale, days in DAYS_OF_THE_WEEK.items()) | |
def day_offset(day_name, day_count, locale): | |
day_number = (DAYS_OF_THE_WEEK[locale][day_name] + day_count) % len(DAYS_OF_THE_WEEK[locale]) | |
return REVERSE_DAYS_OF_THE_WEEK[locale][day_number] | |
# Test cases: | |
assert day_offset("Sunday", 0, "en_US") == "Sunday" | |
assert day_offset("Sunday", 1, "en_US") == "Monday" | |
assert day_offset("Sunday", 2, "en_US") == "Tuesday" | |
assert day_offset("Sunday", 6, "en_US") == "Saturday" | |
assert day_offset("Sunday", 7, "en_US") == "Sunday" | |
assert day_offset("Sunday", 8, "en_US") == "Monday" | |
assert day_offset("Wednesday", 4, "en_US") == "Sunday" | |
assert day_offset("Wednesday", 14, "en_US") == "Wednesday" | |
assert day_offset("Wednesday", 15, "en_US") == "Thursday" | |
assert day_offset("Saturday", 15, "en_US") == "Sunday" | |
assert day_offset("Saturday", -1, "en_US") == "Friday" | |
assert day_offset("Saturday", -14, "en_US") == "Saturday" | |
assert day_offset("Saturday", -16, "en_US") == "Thursday" | |
assert day_offset("Lunes", 3, "es_ES") == "Jueves" | |
assert day_offset("Lunes", 8, "es_ES") == "Martes" | |
assert day_offset("Lunes", -8, "es_ES") == "Domingo" | |
assert day_offset("Lunes", 0, "es_ES") == "Lunes" | |
assert day_offset("Lunes", 0, "es_ES") == "Lunes" | |
assert day_offset("日曜日", 0, "ja_JP") == "日曜日" | |
assert day_offset("日曜日", 2, "ja_JP") == "火曜日" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment