Delete other/date_to_weekday.py as a how-to-use, not an algorithm (#5591)

* [mypy] Fixes typing errors in other/date_to_weekday

* [mypy] uses future annotation style for other/date_to_weekly

* date_to_weekday: new implementation replaces buggy original

* date_to_weekday: add examples from multiple of 100 years

* clean-up: runs `black` to fix formatting

* Delete date_to_weekday.py

Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
Andrew Grangaard 2021-10-29 00:22:57 -07:00 committed by GitHub
parent 0fc24e8629
commit a281151a2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,27 +0,0 @@
from calendar import day_name
from datetime import datetime
def date_to_weekday(inp_date: str) -> str:
"""
It returns the day name of the given date string.
:param inp_date:
:return: String
>>> date_to_weekday("7/8/2035")
'Tuesday'
>>> date_to_weekday("7/8/2021")
'Saturday'
>>> date_to_weekday("1/1/2021")
'Friday'
"""
day, month, year = (int(x) for x in inp_date.split("/"))
if year % 100 == 0:
year = "00"
new_base_date: str = f"{day}/{month}/{year%100} 0:0:0"
date_time_obj: datetime.date = datetime.strptime(new_base_date, "%d/%m/%y %H:%M:%S")
out_put_day: int = date_time_obj.weekday()
return day_name[out_put_day]
if __name__ == "__main__":
print(date_to_weekday("1/1/2021"), end=" ")