Coverage for otaku_info/utils/dates.py: 67%

Shortcuts on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

10 statements  

1"""LICENSE 

2Copyright 2020 Hermann Krumrey <hermann@krumreyh.com> 

3 

4This file is part of otaku-info. 

5 

6otaku-info is free software: you can redistribute it and/or modify 

7it under the terms of the GNU General Public License as published by 

8the Free Software Foundation, either version 3 of the License, or 

9(at your option) any later version. 

10 

11otaku-info is distributed in the hope that it will be useful, 

12but WITHOUT ANY WARRANTY; without even the implied warranty of 

13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

14GNU General Public License for more details. 

15 

16You should have received a copy of the GNU General Public License 

17along with otaku-info. If not, see <http://www.gnu.org/licenses/>. 

18LICENSE""" 

19 

20from typing import Optional 

21 

22MONTHS = [ 

23 "january", "february", "march", "april", 

24 "may", "june", "july", "august", 

25 "september", "october", "november", "december" 

26] 

27 

28 

29def map_month_name_to_month_number(month_name: str) -> Optional[int]: 

30 """ 

31 Maps month names to month numbers 

32 :param month_name: The name of the month 

33 :return: The month number 

34 """ 

35 month_name_mapping = {name: i + 1 for i, name in enumerate(MONTHS)} 

36 return month_name_mapping.get(month_name.lower()) 

37 

38 

39def map_month_number_to_month_name(month_number: int) -> Optional[str]: 

40 """ 

41 Maps month numbers to month names 

42 :param month_number: The month number 

43 :return: The name of the month 

44 """ 

45 try: 

46 return MONTHS[month_number - 1] 

47 except IndexError: 

48 return None