From 2ac38e88d11e7e1f5cfebc72905d47cb3323981a Mon Sep 17 00:00:00 2001 From: joffrey3 Date: Wed, 15 Nov 2023 16:37:10 +0100 Subject: [PATCH 1/4] =?UTF-8?q?fin=20verif=20date=20et=20d=C3=A9but=20algo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __main__.py | 15 ++++++- doomsday/algorithm.py | 36 +++++++++++++++- doomsday/date.py | 99 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+), 2 deletions(-) diff --git a/__main__.py b/__main__.py index 53c2c43..e7fb779 100644 --- a/__main__.py +++ b/__main__.py @@ -1,5 +1,18 @@ +import doomsday.date as date +import doomsday.algorithm as algorithm + + def main() -> None: - print("Hello world") + """main function ask a date, if the date is incorrect ask again, + when the date is correct, + main function ask for the day of the date and return it to the user""" + + print("Veuillez entrer une date" + + "si vous voulez connaitre son jour dans la semaine.") + input_date: str = input() + while (not date.is_valid_date(input_date)): + input_date = input() + #algorithm.get_weekday_for_date(input_date) main() diff --git a/doomsday/algorithm.py b/doomsday/algorithm.py index cf81d60..5eb674e 100644 --- a/doomsday/algorithm.py +++ b/doomsday/algorithm.py @@ -1,2 +1,36 @@ def get_weekday_for_date(date: str) -> str: - return "Sunday" + """get_weekday_for_date need the anchor date + and then find the day of the date""" + + list_date: list[str] = date.split('-') + + anchor_day_week: str = get_anchor_day(int(list_date[0])) + + anchor_day_in_date_month=find_anchor_day_in_date_month(int(list_date[1])) + + distance_in_day=get_anchor_day(int(list_date[2]),anchor_day_in_date_month): + + return get_day_in_week(anchor_day_week,distance_in_day) + + +def get_anchor_day(year: int) -> str : + + number_for_day: int = year % 100 + number_for_day = add_eleven_if_is_odd(number_for_day) + number_for_day //= 2 + number_for_day = add_eleven_if_is_odd(number_for_day) + number_for_day = get_difference_near_multiple_of_seven(number_for_day) + number_for_day.add_century_step(year//100*100) + number_for_day %= 7 + return change_into_str[number_for_day] + + +def add_eleven_if_is_odd(number: int) -> int : + return number if number % 2 == 0 else number + 11 + + +def get_difference_near_multiple_of_seven(number: int) -> int : + return get_multiple_of_seven() + +def add_century_step(century: int) -> int : + return tab_change_for_century[(century/100)%4] \ No newline at end of file diff --git a/doomsday/date.py b/doomsday/date.py index 0f8e737..be38fbe 100644 --- a/doomsday/date.py +++ b/doomsday/date.py @@ -1,2 +1,101 @@ +error_code_wrong_format: int = (1) +error_code_not_number: int = (2) +error_code_date_not_exist: int = (3) +error_code_year_before_1583: int = (4) + +max_month_last_day: int = (31) +min_month_last_day: int = (30) +special_month_last_day: int = (28) + +year: int = (0) +month: int = (1) +day: int = (2) + + def is_valid_date(date: str) -> bool: + """is_valid_date test conditions for have a correct date """ + + date_list: list[str] = date.split('-') + # Verify the format of the date 'YYYY-MM-DD' + if (len(date_list) != 3): + return List_of_possible_error(error_code_wrong_format, date) + + # Verify that each part of the date is int + date_list_int: list[int] = [] + for element in date_list: + if (not element.isnumeric()): + return List_of_possible_error( + error_code_not_number, date_list[0]) + date_list_int.append(int(element)) + + # Verify that the date is possible Month(1-12) Day(1-lastday) + + if (date_list_int[month] < 1 or + date_list_int[month] > 12): + return List_of_possible_error( + error_code_date_not_exist, date_list[month]) + + if (date_list_int[day] < 1 or + date_list_int[day] > + Month_last_day(date_list_int[month], date_list_int[year])): + return List_of_possible_error( + error_code_date_not_exist, date_list[2]) + + # Verify that the year of the date is after 1583 + if (date_list_int[year] < 1583): + return List_of_possible_error( + error_code_year_before_1583, date_list[0]) + return True + + +def List_of_possible_error(error_code: int, error_text: str) -> bool: + """create an error message with a code and a text""" + + if (error_code == error_code_wrong_format): + print('Erreur, ' + + error_text + + ' n est pas un bon format pour une date.' + + ' Le format demandé est YYYY-MM-DD.') + + if (error_code == error_code_not_number): + print('Erreur, ' + + error_text + + ' n est pas un nombre.') + + if (error_code == error_code_date_not_exist): + print('Erreur, ' + + error_text + + ' le mois ou le jour sont incorrects.') + + if (error_code == error_code_year_before_1583): + print('Erreur, ' + + error_text + + ' l année ne doit pas etre en dessous de 1583.') + + return False + + +def Month_last_day(month_number: int, year: int) -> int: + """Month_last_day take number of the month + and return the last day of month""" + + # Case 31 + if ((month_number % 2 == 1 and month_number <= 7) or + (month_number % 2 == 0 and month_number >= 8)): + return max_month_last_day + + # Case 28-29 + if (month_number == 2): + return leap_year(year) + + # Case 30 + return min_month_last_day + + +def leap_year(year: int) -> int: + """return if year if leap or not""" + + if year % 4 == 0 and (not year % 100 == 0 or year % 400 == 0): + return 29 + return 28 From 5b439dea9c08450e787aeb3092e9bf01fed31913 Mon Sep 17 00:00:00 2001 From: joffrey3 Date: Thu, 16 Nov 2023 20:10:15 +0100 Subject: [PATCH 2/4] fin de l'agorithme du jour --- __main__.py | 5 +-- doomsday/algorithm.py | 94 +++++++++++++++++++++++++++++++++++-------- doomsday/date.py | 71 ++++++++++++++++---------------- 3 files changed, 115 insertions(+), 55 deletions(-) diff --git a/__main__.py b/__main__.py index e7fb779..358211c 100644 --- a/__main__.py +++ b/__main__.py @@ -7,12 +7,11 @@ def main() -> None: when the date is correct, main function ask for the day of the date and return it to the user""" - print("Veuillez entrer une date" + - "si vous voulez connaitre son jour dans la semaine.") + print("Please enter a date if you want to know it day on week") input_date: str = input() while (not date.is_valid_date(input_date)): input_date = input() - #algorithm.get_weekday_for_date(input_date) + print(input_date + " is a " + algorithm.get_weekday_for_date(input_date)) main() diff --git a/doomsday/algorithm.py b/doomsday/algorithm.py index 5eb674e..7c2a25a 100644 --- a/doomsday/algorithm.py +++ b/doomsday/algorithm.py @@ -1,36 +1,96 @@ +import doomsday.date as date + +WEEK_DAY_STR = ("Sunday", "Monday", "Tuesday", "Wednesday", + "Thursday", "Friday", "Saturday") + +TAB_CHANGE_FOR_CENTURY = (2, 0, 5, 3) +TAB_ANCHOR_DAY_IN_MONTH = (10, 21, 0, 4, 9, 6, 11, 8, 5, 10, 7, 12) + +NUMBER_ADD_IF_ODD = 11 +WEEK_SIZE = 7 +CENTURY = 100 + +YEAR = 0 +MONTH = 1 +DAY = 2 + + def get_weekday_for_date(date: str) -> str: - """get_weekday_for_date need the anchor date + """get_weekday_for_date need the anchor date and then find the day of the date""" + # We split again the date list_date: list[str] = date.split('-') - anchor_day_week: str = get_anchor_day(int(list_date[0])) + # We find the anchor day + anchor_day_week: int = get_anchor_day(int(list_date[YEAR])) - anchor_day_in_date_month=find_anchor_day_in_date_month(int(list_date[1])) + # With the month we find the anchor day in the month + anchor_day_in_date_month = find_anchor_day_in_date_month( + int(list_date[MONTH]), int(list_date[YEAR])) - distance_in_day=get_anchor_day(int(list_date[2]),anchor_day_in_date_month): + # We return the str day in week + return get_day_in_week(anchor_day_week, + anchor_day_in_date_month, list_date) - return get_day_in_week(anchor_day_week,distance_in_day) +def get_anchor_day(year: int) -> int: + """get_anchor_day find the anchor day with different operation""" -def get_anchor_day(year: int) -> str : + # We keep only the two last number of the year + number_for_day: int = year % CENTURY - number_for_day: int = year % 100 - number_for_day = add_eleven_if_is_odd(number_for_day) + # We transform this number + number_for_day = add_eleven_if_is_odd(number_for_day) number_for_day //= 2 number_for_day = add_eleven_if_is_odd(number_for_day) number_for_day = get_difference_near_multiple_of_seven(number_for_day) - number_for_day.add_century_step(year//100*100) - number_for_day %= 7 - return change_into_str[number_for_day] + number_for_day = add_century_step( + number_for_day, year // CENTURY * CENTURY) % WEEK_SIZE + + # We find the day in a tab + return number_for_day + + +def add_eleven_if_is_odd(number: int) -> int: + """We add eleven if number is odd""" + return number if number % 2 == 0 else number + NUMBER_ADD_IF_ODD + + +def get_difference_near_multiple_of_seven(number: int) -> int: + """We take difference between number and multiple of seven above""" + return get_multiple_of_seven_above(number)-number + + +def get_multiple_of_seven_above(number: int) -> int: + """We find the multiple of seven above the number""" + number = number // WEEK_SIZE * WEEK_SIZE + if number % WEEK_SIZE != 0: + number += WEEK_SIZE + return number + + +def add_century_step(number: int, century: int) -> int: + """we add a number different with the century""" + return number+TAB_CHANGE_FOR_CENTURY[(century // CENTURY) % + len(TAB_CHANGE_FOR_CENTURY)] + +def find_anchor_day_in_date_month(month: int, year: int) -> int: + """anchor day in month who is in a tab""" + if (month < 3 and date.get_leap(year)): + return TAB_ANCHOR_DAY_IN_MONTH[month-1] + 1 + return TAB_ANCHOR_DAY_IN_MONTH[month-1] -def add_eleven_if_is_odd(number: int) -> int : - return number if number % 2 == 0 else number + 11 +def get_difference_in_day(current_day: int, anchor_day: int) -> int: + """get difference between anchor day and current day""" + return current_day - anchor_day -def get_difference_near_multiple_of_seven(number: int) -> int : - return get_multiple_of_seven() -def add_century_step(century: int) -> int : - return tab_change_for_century[(century/100)%4] \ No newline at end of file +def get_day_in_week(anchor_day: int, anchor_day_in_date_month: int, + list_date: list[str]) -> str: + """get_day_in_week translate anchor to day we search with distance""" + distance_in_day = get_difference_in_day(int(list_date[DAY]), + anchor_day_in_date_month) + return WEEK_DAY_STR[(anchor_day+distance_in_day) % WEEK_SIZE] diff --git a/doomsday/date.py b/doomsday/date.py index be38fbe..958b4a6 100644 --- a/doomsday/date.py +++ b/doomsday/date.py @@ -1,15 +1,16 @@ -error_code_wrong_format: int = (1) -error_code_not_number: int = (2) -error_code_date_not_exist: int = (3) -error_code_year_before_1583: int = (4) +ERROR_CODE_WRONG_FORMAT = (1) +ERROR_CODE_NOT_NUMBER = (2) +ERROR_CODE_DATE_NOT_EXIST = (3) +ERROR_CODE_YEAR_BEFORE_1583 = (4) -max_month_last_day: int = (31) -min_month_last_day: int = (30) -special_month_last_day: int = (28) +MAX_MONTH_LAST_DAY = (31) +MIN_MONTH_LAST_DAY = (30) +SPECIAL_MONTH_LAST_DAY = (28) +SPECIAL_MONTH_LAST_LEAD_DAY = (29) -year: int = (0) -month: int = (1) -day: int = (2) +YEAR = (0) +MONTH = (1) +DAY = (2) def is_valid_date(date: str) -> bool: @@ -18,33 +19,32 @@ def is_valid_date(date: str) -> bool: date_list: list[str] = date.split('-') # Verify the format of the date 'YYYY-MM-DD' if (len(date_list) != 3): - return List_of_possible_error(error_code_wrong_format, date) + return List_of_possible_error(ERROR_CODE_WRONG_FORMAT, date) # Verify that each part of the date is int date_list_int: list[int] = [] for element in date_list: if (not element.isnumeric()): return List_of_possible_error( - error_code_not_number, date_list[0]) + ERROR_CODE_NOT_NUMBER, date_list[0]) date_list_int.append(int(element)) # Verify that the date is possible Month(1-12) Day(1-lastday) - - if (date_list_int[month] < 1 or - date_list_int[month] > 12): + if (date_list_int[MONTH] < 1 or + date_list_int[MONTH] > 12): return List_of_possible_error( - error_code_date_not_exist, date_list[month]) + ERROR_CODE_DATE_NOT_EXIST, date_list[MONTH]) - if (date_list_int[day] < 1 or - date_list_int[day] > - Month_last_day(date_list_int[month], date_list_int[year])): + if (date_list_int[DAY] < 1 or + date_list_int[DAY] > + Month_last_day(date_list_int[MONTH], date_list_int[YEAR])): return List_of_possible_error( - error_code_date_not_exist, date_list[2]) + ERROR_CODE_DATE_NOT_EXIST, date_list[2]) # Verify that the year of the date is after 1583 - if (date_list_int[year] < 1583): + if (date_list_int[YEAR] < 1583): return List_of_possible_error( - error_code_year_before_1583, date_list[0]) + ERROR_CODE_YEAR_BEFORE_1583, date_list[0]) return True @@ -52,23 +52,23 @@ def is_valid_date(date: str) -> bool: def List_of_possible_error(error_code: int, error_text: str) -> bool: """create an error message with a code and a text""" - if (error_code == error_code_wrong_format): + if (error_code == ERROR_CODE_WRONG_FORMAT): print('Erreur, ' + error_text + ' n est pas un bon format pour une date.' + ' Le format demandé est YYYY-MM-DD.') - if (error_code == error_code_not_number): + if (error_code == ERROR_CODE_NOT_NUMBER): print('Erreur, ' + error_text + ' n est pas un nombre.') - if (error_code == error_code_date_not_exist): + if (error_code == ERROR_CODE_DATE_NOT_EXIST): print('Erreur, ' + error_text + ' le mois ou le jour sont incorrects.') - if (error_code == error_code_year_before_1583): + if (error_code == ERROR_CODE_YEAR_BEFORE_1583): print('Erreur, ' + error_text + ' l année ne doit pas etre en dessous de 1583.') @@ -83,19 +83,20 @@ def Month_last_day(month_number: int, year: int) -> int: # Case 31 if ((month_number % 2 == 1 and month_number <= 7) or (month_number % 2 == 0 and month_number >= 8)): - return max_month_last_day + return MAX_MONTH_LAST_DAY # Case 28-29 if (month_number == 2): - return leap_year(year) + if (get_leap(year)): + return SPECIAL_MONTH_LAST_LEAD_DAY + return SPECIAL_MONTH_LAST_DAY # Case 30 - return min_month_last_day - + return MIN_MONTH_LAST_DAY -def leap_year(year: int) -> int: - """return if year if leap or not""" - if year % 4 == 0 and (not year % 100 == 0 or year % 400 == 0): - return 29 - return 28 +def get_leap(year: int) -> bool: + """change the variable if the year is leap""" + if year % 4 == 0 and ((not year % 100 == 0) or year % 400 == 0): + return True + return False From a653eebe77f3d418be62004f5967865a67830c57 Mon Sep 17 00:00:00 2001 From: joffrey3 Date: Fri, 17 Nov 2023 09:33:13 +0100 Subject: [PATCH 3/4] fin --- __main__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/__main__.py b/__main__.py index 358211c..61b23d8 100644 --- a/__main__.py +++ b/__main__.py @@ -7,10 +7,11 @@ def main() -> None: when the date is correct, main function ask for the day of the date and return it to the user""" - print("Please enter a date if you want to know it day on week") - input_date: str = input() - while (not date.is_valid_date(input_date)): - input_date = input() + while True: + input_date: str = input( + "Please enter a date if you want to know it day on week") + if (date.is_valid_date(input_date)): + break print(input_date + " is a " + algorithm.get_weekday_for_date(input_date)) From b6863878917e3ea251a172b566549b399abfbed3 Mon Sep 17 00:00:00 2001 From: joffrey3 Date: Fri, 17 Nov 2023 11:47:29 +0100 Subject: [PATCH 4/4] =?UTF-8?q?fin=20avec=20la=20revue=20corrig=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doomsday/algorithm.py | 38 ++++++++--------- doomsday/date.py | 94 ++++++++++++++++++++++++------------------- 2 files changed, 72 insertions(+), 60 deletions(-) diff --git a/doomsday/algorithm.py b/doomsday/algorithm.py index 7c2a25a..f5d3bc0 100644 --- a/doomsday/algorithm.py +++ b/doomsday/algorithm.py @@ -1,18 +1,17 @@ -import doomsday.date as date +from doomsday.date import is_leap, Date_part -WEEK_DAY_STR = ("Sunday", "Monday", "Tuesday", "Wednesday", - "Thursday", "Friday", "Saturday") +WEEKDAY = ("Sunday", "Monday", "Tuesday", "Wednesday", + "Thursday", "Friday", "Saturday") -TAB_CHANGE_FOR_CENTURY = (2, 0, 5, 3) -TAB_ANCHOR_DAY_IN_MONTH = (10, 21, 0, 4, 9, 6, 11, 8, 5, 10, 7, 12) +CHANGE_FOR_CENTURY = (2, 0, 5, 3) +ANCHOR_DAY_IN_MONTH = (10, 21, 0, 4, 9, 6, 11, 8, 5, 10, 7, 12) -NUMBER_ADD_IF_ODD = 11 WEEK_SIZE = 7 CENTURY = 100 -YEAR = 0 +"""YEAR = 0 MONTH = 1 -DAY = 2 +DAY = 2""" def get_weekday_for_date(date: str) -> str: @@ -23,11 +22,12 @@ def get_weekday_for_date(date: str) -> str: list_date: list[str] = date.split('-') # We find the anchor day - anchor_day_week: int = get_anchor_day(int(list_date[YEAR])) + anchor_day_week: int = get_anchor_day(int(list_date[Date_part.YEAR.value])) # With the month we find the anchor day in the month anchor_day_in_date_month = find_anchor_day_in_date_month( - int(list_date[MONTH]), int(list_date[YEAR])) + int(list_date[Date_part.MONTH.value]), + int(list_date[Date_part.YEAR.value])) # We return the str day in week return get_day_in_week(anchor_day_week, @@ -54,7 +54,7 @@ def get_anchor_day(year: int) -> int: def add_eleven_if_is_odd(number: int) -> int: """We add eleven if number is odd""" - return number if number % 2 == 0 else number + NUMBER_ADD_IF_ODD + return number if number % 2 == 0 else number + 11 def get_difference_near_multiple_of_seven(number: int) -> int: @@ -72,15 +72,15 @@ def get_multiple_of_seven_above(number: int) -> int: def add_century_step(number: int, century: int) -> int: """we add a number different with the century""" - return number+TAB_CHANGE_FOR_CENTURY[(century // CENTURY) % - len(TAB_CHANGE_FOR_CENTURY)] + return number + CHANGE_FOR_CENTURY[(century // CENTURY) % + len(CHANGE_FOR_CENTURY)] def find_anchor_day_in_date_month(month: int, year: int) -> int: """anchor day in month who is in a tab""" - if (month < 3 and date.get_leap(year)): - return TAB_ANCHOR_DAY_IN_MONTH[month-1] + 1 - return TAB_ANCHOR_DAY_IN_MONTH[month-1] + if (month < 3 and is_leap(year)): + return ANCHOR_DAY_IN_MONTH[month-1] + 1 + return ANCHOR_DAY_IN_MONTH[month-1] def get_difference_in_day(current_day: int, anchor_day: int) -> int: @@ -91,6 +91,6 @@ def get_difference_in_day(current_day: int, anchor_day: int) -> int: def get_day_in_week(anchor_day: int, anchor_day_in_date_month: int, list_date: list[str]) -> str: """get_day_in_week translate anchor to day we search with distance""" - distance_in_day = get_difference_in_day(int(list_date[DAY]), - anchor_day_in_date_month) - return WEEK_DAY_STR[(anchor_day+distance_in_day) % WEEK_SIZE] + distance_in_day = get_difference_in_day( + int(list_date[Date_part.DAY.value]), anchor_day_in_date_month) + return WEEKDAY[(anchor_day+distance_in_day) % WEEK_SIZE] diff --git a/doomsday/date.py b/doomsday/date.py index 958b4a6..10bfa8c 100644 --- a/doomsday/date.py +++ b/doomsday/date.py @@ -1,16 +1,27 @@ -ERROR_CODE_WRONG_FORMAT = (1) -ERROR_CODE_NOT_NUMBER = (2) -ERROR_CODE_DATE_NOT_EXIST = (3) -ERROR_CODE_YEAR_BEFORE_1583 = (4) +from enum import Enum, unique, auto -MAX_MONTH_LAST_DAY = (31) -MIN_MONTH_LAST_DAY = (30) -SPECIAL_MONTH_LAST_DAY = (28) -SPECIAL_MONTH_LAST_LEAD_DAY = (29) -YEAR = (0) -MONTH = (1) -DAY = (2) +@unique +class Error(Enum): + WRONG_FORMAT = auto() + NOT_NUMBER = auto() + DATE_NOT_EXIST = auto() + YEAR_BEFORE_1583 = auto() + + +@unique +class Last_day(Enum): + SPECIAL_MONTH = 28 + SPECIAL_MONTH_LEAP = 29 + MAX_MONTH = 31 + MIN_MONTH = 30 + + +@unique +class Date_part(Enum): + YEAR = 0 + MONTH = 1 + DAY = 2 def is_valid_date(date: str) -> bool: @@ -19,56 +30,57 @@ def is_valid_date(date: str) -> bool: date_list: list[str] = date.split('-') # Verify the format of the date 'YYYY-MM-DD' if (len(date_list) != 3): - return List_of_possible_error(ERROR_CODE_WRONG_FORMAT, date) + return show_error(Error.WRONG_FORMAT, date) # Verify that each part of the date is int date_list_int: list[int] = [] for element in date_list: if (not element.isnumeric()): - return List_of_possible_error( - ERROR_CODE_NOT_NUMBER, date_list[0]) + return show_error( + Error.NOT_NUMBER, date_list[0]) date_list_int.append(int(element)) # Verify that the date is possible Month(1-12) Day(1-lastday) - if (date_list_int[MONTH] < 1 or - date_list_int[MONTH] > 12): - return List_of_possible_error( - ERROR_CODE_DATE_NOT_EXIST, date_list[MONTH]) - - if (date_list_int[DAY] < 1 or - date_list_int[DAY] > - Month_last_day(date_list_int[MONTH], date_list_int[YEAR])): - return List_of_possible_error( - ERROR_CODE_DATE_NOT_EXIST, date_list[2]) + if (date_list_int[Date_part.MONTH.value] < 1 or + date_list_int[Date_part.MONTH.value] > 12): + return show_error( + Error.DATE_NOT_EXIST, date_list[Date_part.MONTH.value]) + + if (date_list_int[Date_part.DAY.value] < 1 or + date_list_int[Date_part.DAY.value] > + find_month_last_day(date_list_int[Date_part.MONTH.value], + date_list_int[Date_part.YEAR.value])): + return show_error( + Error.DATE_NOT_EXIST, date_list[Date_part.DAY.value]) # Verify that the year of the date is after 1583 - if (date_list_int[YEAR] < 1583): - return List_of_possible_error( - ERROR_CODE_YEAR_BEFORE_1583, date_list[0]) + if (date_list_int[Date_part.YEAR.value] < 1583): + return show_error( + Error.YEAR_BEFORE_1583, date_list[Date_part.YEAR.value]) return True -def List_of_possible_error(error_code: int, error_text: str) -> bool: +def show_error(error_code: Error, error_text: str) -> bool: """create an error message with a code and a text""" - if (error_code == ERROR_CODE_WRONG_FORMAT): + if (error_code == Error.WRONG_FORMAT): print('Erreur, ' + error_text + ' n est pas un bon format pour une date.' + ' Le format demandé est YYYY-MM-DD.') - if (error_code == ERROR_CODE_NOT_NUMBER): + if (error_code == Error.NOT_NUMBER): print('Erreur, ' + error_text + ' n est pas un nombre.') - if (error_code == ERROR_CODE_DATE_NOT_EXIST): + if (error_code == Error.DATE_NOT_EXIST): print('Erreur, ' + error_text + ' le mois ou le jour sont incorrects.') - if (error_code == ERROR_CODE_YEAR_BEFORE_1583): + if (error_code == Error.YEAR_BEFORE_1583): print('Erreur, ' + error_text + ' l année ne doit pas etre en dessous de 1583.') @@ -76,27 +88,27 @@ def List_of_possible_error(error_code: int, error_text: str) -> bool: return False -def Month_last_day(month_number: int, year: int) -> int: - """Month_last_day take number of the month +def find_month_last_day(month_number: int, year: int) -> int: + """month_last_day take number of the month and return the last day of month""" # Case 31 if ((month_number % 2 == 1 and month_number <= 7) or (month_number % 2 == 0 and month_number >= 8)): - return MAX_MONTH_LAST_DAY + return Last_day.MAX_MONTH.value # Case 28-29 if (month_number == 2): - if (get_leap(year)): - return SPECIAL_MONTH_LAST_LEAD_DAY - return SPECIAL_MONTH_LAST_DAY + if (is_leap(year)): + return Last_day.SPECIAL_MONTH_LEAP.value + return Last_day.SPECIAL_MONTH.value # Case 30 - return MIN_MONTH_LAST_DAY + return Last_day.MIN_MONTH.value -def get_leap(year: int) -> bool: - """change the variable if the year is leap""" +def is_leap(year: int) -> bool: + """return if the year is leap""" if year % 4 == 0 and ((not year % 100 == 0) or year % 400 == 0): return True return False