-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
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
Delete other/date_to_weekday.py as a how-to-use, not an algorithm #5591
Conversation
b160d84
to
59a3523
Compare
apologies: had to rebase my pr branches to fix my author email address. |
other/date_to_weekday.py
Outdated
@@ -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 comment
The 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 year % 100
thing because not all years that are evenly divisible by 100 are the same year.
>>> [(i, datetime(i, 1, 1).weekday()) for i in range(200, 2200, 100)]
[ (200, 2), (300, 0), (400, 5), (500, 4),
(600, 2), (700, 0), (800, 5), (900, 4),
(1000, 2), (1100, 0), (1200, 5), (1300, 4),
(1400, 2), (1500, 0), (1600, 5), (1700, 4),
(1800, 2), (1900, 0), (2000, 5), (2100, 4)]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 /
, that can be added back in.
other/date_to_weekday.py
Outdated
>>> day_of_week(datetime(year=2000, month=1, day=1)) | ||
'Saturday' | ||
""" | ||
day_of_week: int = datetime_obj.weekday() # Monday = 0 .. Sunday = 6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we keep a full implementation here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My sense is that we should delete the entire file. This is a how-to-use the datetime module, not an algorithm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your effort @spazm but this file has got to go.
@spazm In fact the test cases in b9fee14 can go into https://github.com/TheAlgorithms/Python/blob/master/other/doomsday.py. Feel free to open a new PR |
Describe your change:
Fixes type annotations on other/date_to_weekday.
strptime()
returns adatetime
, not adatetime.date
.int
tostr
is fine in a dynamic language, but the type checker needs to be told it is expected.Before
After
Checklist:
Fixes: #{$ISSUE_NO}
.