nepali 0.5.5__py3-none-any.whl → 1.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. nepali/__init__.py +1 -1
  2. nepali/char.py +102 -81
  3. nepali/constants.py +66 -0
  4. nepali/date_converter.py +334 -0
  5. nepali/datetime/__init__.py +13 -14
  6. nepali/datetime/_datetime.py +391 -402
  7. nepali/datetime/_formatter.py +325 -0
  8. nepali/datetime/_humanize.py +117 -132
  9. nepali/datetime/_nepalimonth.py +118 -0
  10. nepali/datetime/_nepaliweek.py +125 -0
  11. nepali/datetime/parser/__init__.py +4 -4
  12. nepali/datetime/parser/_parser.py +59 -50
  13. nepali/datetime/parser/validators.py +249 -159
  14. nepali/datetime/utils.py +38 -0
  15. nepali/exceptions.py +8 -3
  16. nepali/locations/__init__.py +3 -0
  17. nepali/locations/_data.py +4271 -0
  18. nepali/locations/_locations.py +38 -0
  19. nepali/locations/models.py +104 -0
  20. nepali/locations/utils.py +54 -0
  21. nepali/number/__init__.py +19 -0
  22. nepali/number/_nepalinumber.py +563 -0
  23. nepali/number/_number.py +53 -0
  24. nepali/number/utils.py +72 -0
  25. nepali/phone_number.py +183 -0
  26. nepali/templatetags/__init__.py +0 -0
  27. nepali/templatetags/nepalidatetime.py +194 -24
  28. nepali/templatetags/nepalinumber.py +97 -7
  29. nepali/tests/test_date_converter.py +148 -0
  30. nepali/tests/test_datetime.py +275 -29
  31. nepali/tests/test_humanize.py +78 -7
  32. nepali/tests/test_locations.py +154 -0
  33. nepali/tests/test_nepalimonth.py +152 -0
  34. nepali/tests/test_nepaliweek.py +154 -0
  35. nepali/tests/test_number.py +3152 -0
  36. nepali/tests/test_parser.py +82 -69
  37. nepali/tests/test_phone_number.py +254 -0
  38. nepali/tests/test_timezone.py +192 -0
  39. nepali/timezone.py +50 -7
  40. nepali/utils.py +9 -68
  41. nepali-1.2.0.dist-info/METADATA +476 -0
  42. nepali-1.2.0.dist-info/RECORD +46 -0
  43. {nepali-0.5.5.dist-info → nepali-1.2.0.dist-info}/WHEEL +1 -1
  44. {nepali-0.5.5.dist-info → nepali-1.2.0.dist-info/licenses}/LICENSE +1 -1
  45. {nepali-0.5.5.dist-info → nepali-1.2.0.dist-info}/top_level.txt +0 -0
  46. nepali/datetime/_converter.py +0 -394
  47. nepali/datetime/_formarter.py +0 -314
  48. nepali/datetime.py +0 -1169
  49. nepali/number.py +0 -51
  50. nepali-0.5.5.dist-info/METADATA +0 -220
  51. nepali-0.5.5.dist-info/RECORD +0 -27
nepali/__init__.py CHANGED
@@ -1 +1 @@
1
- name = "nepali"
1
+ name = "nepali"
nepali/char.py CHANGED
@@ -1,106 +1,127 @@
1
- from .number import NepaliNumber
1
+ import warnings
2
2
 
3
+ from . import number
4
+ from .datetime._nepalimonth import nepalimonth
5
+ from .datetime._nepaliweek import nepaliweek
3
6
 
4
7
  MONTHS_MAP = {
5
- 'बैशाख': 'Baishakh',
6
- 'जेठ': 'Jestha',
7
- 'असार': 'Ashad',
8
- 'साउन': 'Sharwan',
9
- 'भदौ': 'Bhadra',
10
- 'असोज': 'Ashwin',
11
- 'कात्तिक': 'Kartik',
12
- 'मंसिर': 'Mangsir',
13
- 'पुस': 'Poush',
14
- 'माघ': 'Magh',
15
- 'फागुन': 'Falgun',
16
- 'चैत': 'Chaitra',
8
+ "बैशाख": "Baishakh",
9
+ "जेठ": "Jestha",
10
+ "असार": "Ashad",
11
+ "साउन": "Sharwan",
12
+ "भदौ": "Bhadra",
13
+ "असोज": "Ashwin",
14
+ "कात्तिक": "Kartik",
15
+ "मंसिर": "Mangsir",
16
+ "पुस": "Poush",
17
+ "माघ": "Magh",
18
+ "फागुन": "Falgun",
19
+ "चैत": "Chaitra",
17
20
  }
18
21
 
19
22
  DAYS_MAP = {
20
- 'आइतबार': 'Sunday',
21
- 'सोमबार': 'Monday',
22
- 'मंगलबार': 'Tuesday',
23
- 'बुधबार': 'Wednesday',
24
- 'बिहीबार': 'Thursday',
25
- 'शुक्रबार': 'Friday',
26
- 'शनिबार': 'Saturday',
23
+ "आइतबार": "Sunday",
24
+ "सोमबार": "Monday",
25
+ "मंगलबार": "Tuesday",
26
+ "बुधबार": "Wednesday",
27
+ "बिहीबार": "Thursday",
28
+ "शुक्रबार": "Friday",
29
+ "शनिबार": "Saturday",
27
30
  }
28
31
 
29
32
  HALF_DAYS_MAP = {
30
- 'आइत': 'Sun',
31
- 'सोम': 'Mon',
32
- 'मंगल': 'Tue',
33
- 'बुध': 'Wed',
34
- 'बिही': 'Thu',
35
- 'शुक्र': 'Fri',
36
- 'शनि': 'Sat',
33
+ "आइत": "Sun",
34
+ "सोम": "Mon",
35
+ "मंगल": "Tue",
36
+ "बुध": "Wed",
37
+ "बिही": "Thu",
38
+ "शुक्र": "Fri",
39
+ "शनि": "Sat",
37
40
  }
38
41
 
39
42
  AM_PM_MAP = {
40
- 'शुभप्रभात' : 'AM',
41
- 'मध्यान्ह': 'PM',
42
- 'अपरान्ह': 'PM',
43
+ "शुभप्रभात": "AM",
44
+ "मध्यान्ह": "PM",
45
+ "अपरान्ह": "PM",
43
46
  }
44
47
 
45
48
 
46
-
47
49
  class NepaliChar:
50
+ @staticmethod
51
+ def number(num):
52
+ warnings.warn(
53
+ message="NepaliChar.number has been depreciated and will be removed in the future release.",
54
+ category=DeprecationWarning,
55
+ )
56
+ return number.english_to_nepali(num)
57
+
58
+ @staticmethod
59
+ def day(day):
60
+ warnings.warn(
61
+ message="NepaliChar.day has been depreciated and will be removed in the future release.",
62
+ category=DeprecationWarning,
63
+ )
64
+ return nepaliweek(day).name_ne
65
+
66
+ @staticmethod
67
+ def half_day(day):
68
+ warnings.warn(
69
+ message="NepaliChar.half_day has been depreciated and will be removed in the future release.",
70
+ category=DeprecationWarning,
71
+ )
72
+ return nepaliweek(day).abbr_ne
73
+
74
+ @staticmethod
75
+ def month(month):
76
+ warnings.warn(
77
+ message="NepaliChar.month has been depreciated and will be removed in the future release.",
78
+ category=DeprecationWarning,
79
+ )
80
+ return nepalimonth(month).name_ne
48
81
 
49
- @staticmethod
50
- def number(num):
51
- return NepaliNumber.convert(num)
52
82
 
53
- @staticmethod
54
- def day(day):
55
- days = ['आइतबार','सोमबार','मंगलबार','बुधबार','बिहीबार','शुक्रबार','शनिबार']
56
- return days[day-1]
83
+ class EnglishChar:
84
+ @staticmethod
85
+ def day(day):
86
+ warnings.warn(
87
+ message="EnglishChar.day has been depreciated and will be removed in the future release.",
88
+ category=DeprecationWarning,
89
+ )
90
+ return nepaliweek(day).name
91
+
92
+ @staticmethod
93
+ def half_day(day):
94
+ warnings.warn(
95
+ message="EnglishChar.half_day has been depreciated and will be removed in the future release.",
96
+ category=DeprecationWarning,
97
+ )
98
+ return nepaliweek(day).abbr
99
+
100
+ @staticmethod
101
+ def month(month):
102
+ warnings.warn(
103
+ message="EnglishChar.month has been depreciated and will be removed in the future release.",
104
+ category=DeprecationWarning,
105
+ )
106
+ return nepalimonth(month).name
57
107
 
58
- @staticmethod
59
- def half_day(day):
60
- days = ['आइत','सोम','मंगल','बुध','बिही','शुक्र','शनि']
61
- return days[day-1]
62
108
 
63
- @staticmethod
64
- def month(month):
65
- months = ['बैशाख','जेठ','असार','साउन','भदौ','असोज','कात्तिक','मंसिर','पुस','माघ','फागुन','चैत']
66
- return months[month-1]
109
+ def nepali_to_english_text(text):
110
+ # TODO: optimization
67
111
 
68
- class EnglishChar:
69
- months = ['Baishakh','Jestha','Ashad','Sharwan','Bhadra','Ashwin','Kartik','Mangsir','Poush','Magh','Falgun','Chaitra']
70
- days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']
71
- days_half = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
72
-
73
- @staticmethod
74
- def day(day):
75
- return EnglishChar.days[day-1]
112
+ # replacing months
113
+ for k, v in MONTHS_MAP.items():
114
+ text = text.replace(k, v)
76
115
 
77
- @staticmethod
78
- def half_day(day):
79
- return EnglishChar.days_half[day-1]
116
+ # replacing days
117
+ for k, v in DAYS_MAP.items():
118
+ text = text.replace(k, v)
80
119
 
81
- @staticmethod
82
- def month(month):
83
- return EnglishChar.months[month-1]
120
+ # replacing half days
121
+ for k, v in HALF_DAYS_MAP.items():
122
+ text = text.replace(k, v)
84
123
 
124
+ for k, v in AM_PM_MAP.items():
125
+ text = text.replace(k, v)
85
126
 
86
- def nepali_to_english_text(text):
87
- # TODO: optimization
88
-
89
- from .number import NepaliNumber
90
-
91
- # replacing months
92
- for k,v in MONTHS_MAP.items():
93
- text = text.replace(k, v)
94
-
95
- # replacing days
96
- for k,v in DAYS_MAP.items():
97
- text = text.replace(k, v)
98
-
99
- # replacing half days
100
- for k,v in HALF_DAYS_MAP.items():
101
- text = text.replace(k, v)
102
-
103
- for k,v in AM_PM_MAP.items():
104
- text = text.replace(k, v)
105
-
106
- return NepaliNumber.revert(text)
127
+ return number.nepali_to_english(text)
nepali/constants.py ADDED
@@ -0,0 +1,66 @@
1
+ """
2
+ This files contains constants for the py-Nepali project.
3
+ """
4
+
5
+ # Nepali timezone
6
+ NEPAL_TIMEZONE = "Asia/Kathmandu"
7
+
8
+ # Nepali months in english
9
+ NEPALI_MONTHS_EN = (
10
+ "Baishakh",
11
+ "Jestha",
12
+ "Ashad",
13
+ "Sharwan",
14
+ "Bhadra",
15
+ "Ashwin",
16
+ "Kartik",
17
+ "Mangsir",
18
+ "Poush",
19
+ "Magh",
20
+ "Falgun",
21
+ "Chaitra",
22
+ )
23
+
24
+ # Nepali months in Nepali (devanagari)
25
+ NEPALI_MONTHS_NE = (
26
+ "बैशाख",
27
+ "जेठ",
28
+ "असार",
29
+ "साउन",
30
+ "भदौ",
31
+ "असोज",
32
+ "कात्तिक",
33
+ "मंसिर",
34
+ "पुस",
35
+ "माघ",
36
+ "फागुन",
37
+ "चैत",
38
+ )
39
+
40
+ # Week names in english
41
+ WEEKS_EN = (
42
+ "Sunday",
43
+ "Monday",
44
+ "Tuesday",
45
+ "Wednesday",
46
+ "Thursday",
47
+ "Friday",
48
+ "Saturday",
49
+ )
50
+
51
+ # Week abbreviation name in english
52
+ WEEKS_ABBR_EN = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")
53
+
54
+ # Weeks names in Nepali (devanagari)
55
+ WEEKS_NE = (
56
+ "आइतबार",
57
+ "सोमबार",
58
+ "मंगलबार",
59
+ "बुधबार",
60
+ "बिहीबार",
61
+ "शुक्रबार",
62
+ "शनिबार",
63
+ )
64
+
65
+ # Week abbreviation name in Nepali (devanagari)
66
+ WEEKS_ABBR_NE = ("आइत", "सोम", "मंगल", "बुध", "बिही", "शुक्र", "शनि")
@@ -0,0 +1,334 @@
1
+ """
2
+ This python file contains nepali date converter module.
3
+
4
+ USAGE:
5
+ y, m, d = nepali_date_converter.english_to_nepali(2023, 1, 15)
6
+ y, m, d = nepali_date_converter.nepali_to_english(2079, 10, 1)
7
+ """
8
+
9
+
10
+ class NepaliDateConverter:
11
+ """
12
+ Nepali Date Converter
13
+
14
+ All the functions here contains the method to convert english date to nepali and nepali date to english.
15
+ """
16
+
17
+ # Reference date for conversion is 2000/01/01 BS and 1943/4/14 AD
18
+ NP_INITIAL_YEAR = 2000
19
+ REFERENCE_EN_DATE = (1943, 4, 14)
20
+
21
+ # Nepali months data
22
+ # [
23
+ # ((LIST_OF_MONTHS), TOTAL_DAYS_IN_YEAR),
24
+ # ...
25
+ # ]
26
+ #
27
+ NP_MONTHS_DATA = [
28
+ (
29
+ (30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31),
30
+ 365,
31
+ ), # 2000 BS - 1943/1944 AD
32
+ ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365), # 2001 BS
33
+ ((31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30), 365),
34
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31), 366),
35
+ ((30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31), 365),
36
+ ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
37
+ ((31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30), 365),
38
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31), 366),
39
+ ((31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31), 365),
40
+ ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
41
+ ((31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30), 365),
42
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31), 366),
43
+ ((31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30), 365),
44
+ ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
45
+ ((31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30), 365),
46
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31), 366),
47
+ ((31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30), 365),
48
+ ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
49
+ ((31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30), 365),
50
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31), 366),
51
+ ((31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30), 365),
52
+ ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
53
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30), 365),
54
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31), 366),
55
+ ((31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30), 365),
56
+ ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
57
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31), 366),
58
+ ((30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31), 365),
59
+ ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
60
+ ((31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30), 365),
61
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31), 366),
62
+ ((30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31), 365),
63
+ ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
64
+ ((31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30), 365),
65
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31), 366),
66
+ ((30, 32, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31), 365),
67
+ ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
68
+ ((31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30), 365),
69
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31), 366),
70
+ ((31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30), 365),
71
+ ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
72
+ ((31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30), 365),
73
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31), 366),
74
+ ((31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30), 365),
75
+ ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
76
+ ((31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30), 365),
77
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31), 366),
78
+ ((31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30), 365),
79
+ ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
80
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30), 365),
81
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31), 366), # 2050
82
+ ((31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30), 365),
83
+ ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
84
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30), 365),
85
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31), 366),
86
+ ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
87
+ ((31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30), 365),
88
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31), 366),
89
+ ((30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31), 365),
90
+ ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
91
+ ((31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30), 365),
92
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31), 366),
93
+ ((30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31), 365),
94
+ ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
95
+ ((31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30), 365),
96
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31), 366),
97
+ ((31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31), 365),
98
+ ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
99
+ ((31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30), 365),
100
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31), 366),
101
+ ((31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30), 365), # 2070
102
+ ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
103
+ ((31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30), 365),
104
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31), 366),
105
+ ((31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30), 365),
106
+ ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
107
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30), 365),
108
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31), 366),
109
+ ((31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30), 365),
110
+ ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
111
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30), 365), # 2080
112
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31), 366), # 2081
113
+ ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365), # 2082
114
+ ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
115
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31), 366),
116
+ ((30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31), 365),
117
+ ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
118
+ ((31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30), 365),
119
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31), 366),
120
+ ((30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31), 365),
121
+ ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
122
+ ((31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30), 365),
123
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31), 366),
124
+ ((31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31), 365),
125
+ ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
126
+ ((31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30), 365),
127
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31), 366),
128
+ ((31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30), 365),
129
+ ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
130
+ (
131
+ (31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30),
132
+ 365,
133
+ ), # 2099 BS - 2042/2043 AD
134
+ ]
135
+
136
+ # english month constant data (will never change)
137
+ EN_MONTHS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
138
+ EN_LEAP_YEAR_MONTHS = [
139
+ 31,
140
+ 29,
141
+ 31,
142
+ 30,
143
+ 31,
144
+ 30,
145
+ 31,
146
+ 31,
147
+ 30,
148
+ 31,
149
+ 30,
150
+ 31,
151
+ ] # Leap year months (Just 29 on Feb)
152
+
153
+ @classmethod
154
+ def en_min_year(cls):
155
+ return cls.REFERENCE_EN_DATE[0] + 1
156
+
157
+ @classmethod
158
+ def en_max_year(cls):
159
+ return cls.REFERENCE_EN_DATE[0] + len(cls.NP_MONTHS_DATA) - 1
160
+
161
+ @classmethod
162
+ def np_min_year(cls):
163
+ return cls.NP_INITIAL_YEAR
164
+
165
+ # utility methods
166
+
167
+ @classmethod
168
+ def np_max_year(cls):
169
+ return cls.NP_INITIAL_YEAR + len(cls.NP_MONTHS_DATA) - 1
170
+
171
+ def _is_leap_year(self, year):
172
+ """checks if the english year is leap year or not"""
173
+ if year % 4 == 0:
174
+ if year % 100 == 0:
175
+ return year % 400 == 0
176
+ return True
177
+ return False
178
+
179
+ def _get_en_months(self, year):
180
+ return self.EN_LEAP_YEAR_MONTHS if self._is_leap_year(year) else self.EN_MONTHS
181
+
182
+ #
183
+ # ENGLISH DATE CONVERSION
184
+
185
+ def check_english_date(self, year, month, day):
186
+ if year < self.en_min_year() or year > self.en_max_year():
187
+ return False
188
+ if month < 1 or month > 12:
189
+ return False
190
+ if day < 1 or day > 31:
191
+ return False
192
+ return True
193
+
194
+ def _get_total_days_from_english_date(self, year, month, day):
195
+ """counts and returns total days from the date 0000-01-01"""
196
+ total_days = year * 365 + day
197
+ for i in range(0, month - 1):
198
+ total_days = total_days + self.EN_MONTHS[i]
199
+
200
+ # adding leap days (ie. leap year count)
201
+ if month <= 2: # checking February month (where leap exists)
202
+ year -= 1
203
+ total_days += year // 4 - year // 100 + year // 400
204
+
205
+ return total_days
206
+
207
+ def english_to_nepali(self, year, month, day):
208
+ """
209
+ Converts english date to nepali
210
+ return year, month, day
211
+ """
212
+ # VALIDATION
213
+ # checking if date is in range
214
+ if not self.check_english_date(year, month, day):
215
+ raise ValueError("Date out of range")
216
+
217
+ # REFERENCE
218
+ np_year, np_month, np_day = self.NP_INITIAL_YEAR, 1, 1
219
+
220
+ # DIFFERENCE
221
+ # calculating days count from the reference date
222
+ difference = abs(
223
+ self._get_total_days_from_english_date(year, month, day)
224
+ - self._get_total_days_from_english_date(*self.REFERENCE_EN_DATE)
225
+ )
226
+
227
+ # YEAR
228
+ # Incrementing year until the difference remains less than 365
229
+ year_data_index = 0
230
+ while difference >= self.NP_MONTHS_DATA[year_data_index][1]:
231
+ difference -= self.NP_MONTHS_DATA[year_data_index][1]
232
+ np_year += 1
233
+ year_data_index += 1
234
+
235
+ # MONTH
236
+ # Incrementing month until the difference remains less than next nepali month days (mostly 31)
237
+ i = 0
238
+ while difference >= self.NP_MONTHS_DATA[year_data_index][0][i]:
239
+ difference -= self.NP_MONTHS_DATA[year_data_index][0][i]
240
+ np_month += 1
241
+ i += 1
242
+
243
+ # DAY
244
+ # Remaining difference is the day
245
+ np_day += difference
246
+
247
+ return np_year, np_month, np_day
248
+
249
+ #
250
+ # NEPALI DATE CONVERSION
251
+
252
+ def check_nepali_date(self, year, month, day):
253
+ if year < self.np_min_year() or year > self.np_max_year():
254
+ return False
255
+ if month < 1 or month > 12:
256
+ return False
257
+ if (
258
+ day < 1
259
+ or day > self.NP_MONTHS_DATA[year - self.NP_INITIAL_YEAR][0][month - 1]
260
+ ):
261
+ return False
262
+ return True
263
+
264
+ def _get_total_days_from_nepali_date(self, year, month, day):
265
+ """counts and returns total days from the nepali initial date"""
266
+ total_days = day - 1 # taking ref with Date's day 1, so -1
267
+
268
+ # adding days of months of initial year
269
+ year_index = year - self.NP_INITIAL_YEAR
270
+ for i in range(0, month - 1):
271
+ total_days = total_days + self.NP_MONTHS_DATA[year_index][0][i]
272
+
273
+ # adding days of year
274
+ for i in range(0, year_index):
275
+ total_days = total_days + self.NP_MONTHS_DATA[i][1]
276
+
277
+ return total_days
278
+
279
+ def nepali_to_english(self, year, month, day):
280
+ """
281
+ Converts english date to nepali
282
+ return year, month, day
283
+ """
284
+ # VALIDATION
285
+ # checking if date is in range
286
+ if not self.check_nepali_date(year, month, day):
287
+ raise ValueError("Date out of range")
288
+
289
+ # REFERENCE
290
+ # For absolute reference, moving date to Jan 1
291
+ # Eg. ref: 1943/4/14 => 1943/01/01
292
+ en_year, en_month, en_day = self.REFERENCE_EN_DATE[0], 1, 1
293
+ # calculating difference from the adjusted reference (eg. 1943/4/14 - 1943/01/01)
294
+ ref_year_months = self._get_en_months(en_year)
295
+ reference_diff = (
296
+ sum(ref_year_months[0 : self.REFERENCE_EN_DATE[1] - 1])
297
+ + self.REFERENCE_EN_DATE[2]
298
+ - 1 # day - 1
299
+ )
300
+
301
+ # DIFFERENCE
302
+ # calculating days count from the reference date
303
+ difference = abs(
304
+ self._get_total_days_from_nepali_date(
305
+ year, month, day
306
+ ) # returns total days from initial date (nepali)
307
+ + reference_diff
308
+ )
309
+
310
+ # YEAR
311
+ # Incrementing year until the difference remains less than 365 (or 365)
312
+ while (difference >= 366 and self._is_leap_year(en_year)) or (
313
+ difference >= 365 and not (self._is_leap_year(en_year))
314
+ ):
315
+ difference -= 366 if self._is_leap_year(en_year) else 365
316
+ en_year += 1
317
+
318
+ # MONTH
319
+ # Incrementing month until the difference remains less than next english month (mostly 31)
320
+ month_days = self._get_en_months(en_year)
321
+ i = 0
322
+ while difference >= month_days[i]:
323
+ difference -= month_days[i]
324
+ en_month += 1
325
+ i += 1
326
+
327
+ # DAY
328
+ # Remaining difference is the day
329
+ en_day += difference
330
+
331
+ return en_year, en_month, en_day
332
+
333
+
334
+ converter = NepaliDateConverter()
@@ -1,17 +1,16 @@
1
- from ._datetime import nepalidate, nepalitime, nepalidatetime, NepaliDate, NepaliDateTime, NepaliTime
2
- from ._formarter import NepaliDateTimeFormater
1
+ from ._datetime import nepalidate, nepalidatetime, nepalitime
2
+ from ._formatter import NepaliDateTimeFormatter
3
3
  from ._humanize import HumanizeDateTime, nepalihumanize
4
+ from ._nepalimonth import nepalimonth
5
+ from ._nepaliweek import nepaliweek
4
6
 
5
7
  __all__ = [
6
- 'nepalidate',
7
- 'nepalitime',
8
- 'nepalidatetime',
9
-
10
- 'NepaliDate',
11
- 'NepaliTime',
12
- 'NepaliDateTime',
13
-
14
- 'nepalihumanize',
15
- 'NepaliDateTimeFormater',
16
- 'HumanizeDateTime',
17
- ]
8
+ "nepalidate",
9
+ "nepalitime",
10
+ "nepalidatetime",
11
+ "nepalihumanize",
12
+ "nepalimonth",
13
+ "nepaliweek",
14
+ "NepaliDateTimeFormatter",
15
+ "HumanizeDateTime",
16
+ ]