-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
add date_to_weekday finder method #4599
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
Merged
l3str4nge
merged 10 commits into
TheAlgorithms:master
from
suryapratapsinghsuryavanshi:master
Aug 18, 2021
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
efea8b0
add date_to_weekday finder method
suryapratapsinghsuryavanshi f13e448
reformat date_to_weekday method
suryapratapsinghsuryavanshi 288b0b1
Merge branch 'TheAlgorithms:master' into master
suryapratapsinghsuryavanshi 439e05b
remove time
suryapratapsinghsuryavanshi cca826b
remove hardcode weekdays list
suryapratapsinghsuryavanshi c4b8d78
Merge branch 'master' of https://github.com/suryapratapsinghsuryavans…
suryapratapsinghsuryavanshi aef9a59
fix return type error
suryapratapsinghsuryavanshi 13a0c8a
fixing fail issue
suryapratapsinghsuryavanshi 2d7fe0c
Finding the test failing issue
suryapratapsinghsuryavanshi b109686
after testing the pre-commit in local environment
suryapratapsinghsuryavanshi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
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_list: list = [ | ||
"Monday", | ||
"Tuesday", | ||
"Wednesday", | ||
"Thursday", | ||
"Friday", | ||
"Saturday", | ||
"Sunday", | ||
] | ||
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} 23:15:59" | ||
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. I think we don't need a time here. |
||
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_list[out_put_day] | ||
|
||
|
||
if __name__ == "__main__": | ||
print(date_to_weekday("1/1/2021"), end=" ") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We have pretty module in python so we don't need to hardcode weekdays
import calendar;calendar.day_name