-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Delete other/date_to_weekday.py as a how-to-use, not an algorithm #5591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
59a3523
4bbe7ab
4c2425a
a053227
b9fee14
7f8f2e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from calendar import day_name | ||
from datetime import datetime | ||
from typing import Union | ||
|
||
|
||
def date_to_weekday(inp_date: str) -> str: | ||
|
@@ -14,11 +15,12 @@ def date_to_weekday(inp_date: str) -> str: | |
>>> date_to_weekday("1/1/2021") | ||
'Friday' | ||
""" | ||
year: Union[int, str] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of: from typing import Union
year: Union[int, str]
# this repo has been moving to the new syntax by doing
from __future__ import annotations
year: int | str # or year: [int | str] However, I question the base logic of the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The algorithm was definitely flawed. I just wanted to add types :) I've rewritten the algo, which boils it down to two calls to the standard lib. If we want to manually parse a string by splitting on |
||
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") | ||
date_time_obj: datetime = 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] | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.