-
Notifications
You must be signed in to change notification settings - Fork 37
Rendu Timothée #29
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
Open
TimoMet
wants to merge
5
commits into
bcalou:main
Choose a base branch
from
TimoMet:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Rendu Timothée #29
Changes from all commits
Commits
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 |
|---|---|---|
| @@ -1,5 +1,14 @@ | ||
| from doomsday.algorithm import get_weekday_for_date | ||
| from doomsday.date import is_valid_date | ||
|
|
||
|
|
||
| def main() -> None: | ||
| print("Hello world") | ||
| user_input = input("Please enter a date in the format YYYY-MM-dd: ") | ||
|
|
||
| if is_valid_date(user_input): | ||
| print(f"The weekday for {user_input} is: {get_weekday_for_date(user_input)}") | ||
| else: | ||
| print("Error: The date is not valid.") | ||
|
|
||
|
|
||
| main() |
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 |
|---|---|---|
| @@ -1,2 +1,52 @@ | ||
| DAYS: tuple[str, str, str, str, str, str, str] = ( | ||
| 'Sunday', | ||
| 'Monday', | ||
| 'Tuesday', | ||
| 'Wednesday', | ||
| 'Thursday', | ||
| 'Friday', | ||
| 'Saturday' | ||
| ) | ||
|
|
||
|
|
||
| def get_weekday_for_date(date: str) -> str: | ||
| return "Sunday" | ||
| """Returns the weekday for the given date in the format YYYY-MM-dd.""" | ||
| year, month, day = (int(i) for i in date.split('-')) | ||
|
|
||
| anchor_day_index: int = get_anchor_of_the_year(year) | ||
|
|
||
| doomsday_month: list[int] = [3, 7, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5] | ||
|
|
||
| if is_leap_year(year): | ||
| doomsday_month[0] = 4 | ||
| doomsday_month[1] = 1 | ||
|
|
||
| # Calculate the difference between the day and the doomsday of the month | ||
| difference: int = day - doomsday_month[month - 1] | ||
| # Calculate the weekday index by using the anchor day index and the difference | ||
| weekday_index: int = (anchor_day_index + difference) % 7 | ||
|
|
||
| return DAYS[weekday_index] | ||
|
|
||
|
|
||
| def is_leap_year(year: int) -> bool: | ||
| """Checks if the given year is a leap year.""" | ||
| return year % 400 == 0 or (year % 100 != 0 and year % 4 == 0) | ||
|
|
||
|
|
||
| def get_anchor_of_the_year(year: int) -> int: | ||
| """Calculates the anchor day index for the given year.""" | ||
| value: int = year % 100 | ||
|
|
||
| if value % 2 == 1: | ||
| value += 11 | ||
| value //= 2 | ||
| if value % 2 == 1: | ||
| value += 11 | ||
|
|
||
| # multiple of 7 equals or greater than century year | ||
| difference_multiple_of_7: int = (7 - value) % 7 | ||
|
|
||
| numbers_to_add_by_century_year: list[int] = [2, 0, 5, 3] | ||
|
|
||
| return (difference_multiple_of_7 + numbers_to_add_by_century_year[(year // 100) % 4]) % 7 | ||
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 |
|---|---|---|
| @@ -1,2 +1,25 @@ | ||
| def is_valid_date(date: str) -> bool: | ||
| return True | ||
| from datetime import datetime | ||
|
|
||
|
|
||
| def is_valid_date(date_str: str) -> bool: | ||
| """Checks if the given date is valid.""" | ||
| try: | ||
| # Try to convert the string to a date object | ||
| date_obj: datetime = datetime.strptime(date_str, '%Y-%m-%d') | ||
|
|
||
| # Check if the year is greater than or equal to 1583 | ||
| if date_obj.year < 1583: | ||
| print("Error: The year must be greater than or equal to 1583.") | ||
| return False | ||
|
|
||
| return True | ||
|
|
||
| except ValueError: | ||
| # Conversion error, the date is not in the expected format | ||
| print("Error: The date does not follow the format YYYY-MM-dd.") | ||
| return False | ||
|
|
||
| except Exception as e: | ||
| # Handle other potential errors | ||
| print(f"An error occurred: {e}") | ||
| return False |
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.
Bien !