Skip to content

Instantly share code, notes, and snippets.

@routevegetable
Created March 9, 2022 22:56
Show Gist options
  • Save routevegetable/ec99b3ccd91808ccaa7ce23c3446fbcc to your computer and use it in GitHub Desktop.
Save routevegetable/ec99b3ccd91808ccaa7ce23c3446fbcc to your computer and use it in GitHub Desktop.
months = [
("January", 3),
("February", 0),
("March", 3),
("April", 2),
("May", 3),
("June", 2),
("July", 3),
("August", 3),
("September", 2),
("October", 3),
("November", 2),
("December", 3)
]
days = [
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday"
]
def day_to_number(day):
if type(day) == str:
for i in range(0, 7):
if day == days[i]:
return i
else:
return day
def day_to_text(day):
return days[day]
def month_to_number(month):
if type(month) == str:
for i in range(0, 12):
if month == months[i][0]:
return i
else:
return month
def month_to_text(month):
return months[month][0]
def get_future_day(ref_month, ref_date, ref_day, target_month, target_date):
ref_day = day_to_number(ref_day)
ref_month = month_to_number(ref_month)
target_month = month_to_number(target_month)
residual = 0
i = ref_month
while True:
if i == target_month:
break
residual = (residual + months[i][1]) % 7
i = (i + 1) % 12
day = (ref_day + residual + (target_date - ref_date)) % 7
return day_to_text(day)
print(get_future_day("March", 9, "Wednesday",
"June", 15))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment