arabic-datetime 0.0.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.
@@ -0,0 +1,2 @@
1
+ from . arabic_date import Arabic_Date
2
+ from . arabic_time import Arabic_Time
@@ -0,0 +1,139 @@
1
+ from typing import Union
2
+ import datetime
3
+
4
+ # Import constants
5
+ from . constants import MONTH_GROUPS, AR_NUMS
6
+
7
+
8
+ class Arabic_Date:
9
+ def __init__(self, date_object: Union[datetime.date, datetime.datetime]) -> None:
10
+ if not isinstance(date_object, datetime.date) and not isinstance(date_object, datetime.datetime):
11
+ raise TypeError(
12
+ "Arabic_Date class error: The parameter provided to the instance is not a datetime.date object nor a datetime.datetime object.")
13
+
14
+ self.date_object = date_object
15
+
16
+ self.__year = str(self.date_object.year)
17
+ self.__month = int(self.date_object.month)
18
+ # convert first to `int` to turn 01 into 1
19
+ self.__day = str(int(self.date_object.day))
20
+
21
+ # string keys in translate table must be of length 1
22
+ self.num_trans_table = str.maketrans(AR_NUMS)
23
+
24
+ # Group Name Methods
25
+ def syriac_names(self, east_nums: bool = False) -> str:
26
+ if not isinstance(east_nums, bool):
27
+ raise TypeError(
28
+ f"Arabic_Date class error: east_nums must be a boolean. '{east_nums}' is not boolean and was passed to the class method '{self.syriac_names.__name__}'.")
29
+
30
+ if east_nums:
31
+ return self.__day.translate(self.num_trans_table) + " " + MONTH_GROUPS["syriac"]["months"][self.__month-1] + " " + self.__year.translate(self.num_trans_table)
32
+ else:
33
+ return self.__day + " " + MONTH_GROUPS["syriac"]["months"][self.__month-1] + " " + self.__year
34
+
35
+ def roman1_names(self, east_nums: bool = False) -> str:
36
+ if not isinstance(east_nums, bool):
37
+ raise TypeError(
38
+ f"Arabic_Date class error: east_nums must be a boolean. '{east_nums}' is not boolean and was passed to the class method '{self.roman1_names.__name__}'.")
39
+
40
+ if east_nums:
41
+ return self.__day.translate(self.num_trans_table) + " " + MONTH_GROUPS["roman1"]["months"][self.__month-1] + " " + self.__year.translate(self.num_trans_table)
42
+ else:
43
+ return self.__day + " " + MONTH_GROUPS["roman1"]["months"][self.__month-1] + " " + self.__year
44
+
45
+ def roman2_names(self, east_nums: bool = False) -> str:
46
+ if not isinstance(east_nums, bool):
47
+ raise TypeError(
48
+ f"Arabic_Date class error: east_nums must be a boolean. '{east_nums}' is not boolean and was passed to the class method '{self.roman2_names.__name__}'.")
49
+
50
+ if east_nums:
51
+ return self.__day.translate(self.num_trans_table) + " " + MONTH_GROUPS["roman2"]["months"][self.__month-1] + " " + self.__year.translate(self.num_trans_table)
52
+ else:
53
+ return self.__day + " " + MONTH_GROUPS["roman2"]["months"][self.__month-1] + " " + self.__year
54
+
55
+ def french_names(self, east_nums: bool = False) -> str:
56
+ if not isinstance(east_nums, bool):
57
+ raise TypeError(
58
+ f"Arabic_Date class error: east_nums must be a boolean. '{east_nums}' is not boolean and was passed to the class method '{self.french_names.__name__}'.")
59
+
60
+ if east_nums:
61
+ return self.__day.translate(self.num_trans_table) + " " + MONTH_GROUPS["french"]["months"][self.__month-1] + " " + self.__year.translate(self.num_trans_table)
62
+ else:
63
+ return self.__day + " " + MONTH_GROUPS["french"]["months"][self.__month-1] + " " + self.__year
64
+
65
+ # Dual Name Method
66
+ def dual_names(self, first: str, second: str, east_nums: bool = False) -> str:
67
+ if not isinstance(first, str):
68
+ raise TypeError(
69
+ f"Arabic_Date class error: Unknown month group name: '{first}' passed as a parameter to the method '{self.dual_names.__name__}'.")
70
+ elif not isinstance(second, str):
71
+ raise TypeError(
72
+ f"Arabic_Date class error: Unknown month group name: '{second}' passed as a parameter to the method '{self.dual_names.__name__}'.")
73
+ elif not isinstance(east_nums, bool):
74
+ raise TypeError(
75
+ f"Arabic_Date class error: east_nums must be a boolean. '{east_nums}' is not boolean and was passed to the method '{self.dual_names.__name__}'.")
76
+
77
+ if first.strip().lower() == second.strip().lower():
78
+ raise ValueError(
79
+ f"Arabic_Date class error: The first group name and the second group name sould not be identicial: '{first}' was passed as the first and the second parameter to the method {self.dual_names.__name__}. Note that these particular parameters are not case sensitive.")
80
+ valid_first_group = False
81
+ valid_second_group = False
82
+ for group, _ in MONTH_GROUPS.items():
83
+ if first.lower() in group:
84
+ valid_first_group = True
85
+ for group, _ in MONTH_GROUPS.items():
86
+ if second.lower() in group:
87
+ valid_second_group = True
88
+ if not valid_first_group or not valid_second_group:
89
+ error_submessage = ""
90
+ if not valid_first_group:
91
+ error_submessage += f"Unknown first groupe name '{
92
+ first}'"
93
+ if not valid_second_group:
94
+ if error_submessage == "":
95
+ error_submessage += f"Unknown second groupe name '{
96
+ second}'"
97
+ else:
98
+ error_submessage += f" and also unknown second groupe name '{
99
+ second}'"
100
+ raise ValueError(
101
+ f"Arabic_Date class error: {error_submessage} in the parameters passed to the method '{self.dual_names.__name__}'.")
102
+
103
+ if east_nums == True:
104
+ return self.__day.translate(self.num_trans_table) + " " + MONTH_GROUPS[first]["months"][self.__month-1] + " (" + MONTH_GROUPS[second]["months"][self.__month-1] + ") " + self.__year.translate(self.num_trans_table)
105
+ else:
106
+ return self.__day + " " + MONTH_GROUPS[first]["months"][self.__month-1] + " (" + MONTH_GROUPS[second]["months"][self.__month-1] + ") " + self.__year
107
+
108
+ # Date By Country Code Method
109
+ def by_country_code(self, country_code: str, east_nums: bool = None) -> str:
110
+ if not isinstance(country_code, str):
111
+ raise TypeError(
112
+ f"Arabic_Date class error: The 'country_code' parameter passed to the class method '{self.by_country_code.__name__}' is not a string.")
113
+
114
+ elif east_nums is not None and not isinstance(east_nums, bool):
115
+ raise TypeError(
116
+ f"Arabic_Date class error: east_nums must be a boolean. '{east_nums}' is not boolean and was passed to the class method '{self.french_names.__name__}'.")
117
+
118
+ for _, group in MONTH_GROUPS.items():
119
+ if country_code.upper() in group["countries"]:
120
+ if east_nums is not None and east_nums:
121
+ return self.__day.translate(self.num_trans_table) + " " + group["months"][self.__month-1] + " " + self.__year.translate(self.num_trans_table)
122
+ elif east_nums is not None and not east_nums:
123
+ return self.__day + " " + group["months"][self.__month-1] + " " + self.__year
124
+ else:
125
+ if group["east_nums"]:
126
+ return self.__day.translate(self.num_trans_table) + " " + group["months"][self.__month-1] + " " + self.__year.translate(self.num_trans_table)
127
+ else:
128
+ return self.__day + " " + group["months"][self.__month-1] + " " + self.__year
129
+
130
+ else:
131
+ raise ValueError(
132
+ f"Arabic_Date class error: Unknown country code '{country_code}' passed to the class method '{self.by_country_code.__name__}'.")
133
+
134
+ # Eastern Numeric Date Method
135
+ def eastern_numeric_date(self, separator: str = "/") -> str:
136
+ if not isinstance(separator, str):
137
+ raise TypeError(
138
+ f"Arabic_Date class error: The 'separator' parameter passed to the class method '{self.eastern_numeric_date.__name__}' is not a string.")
139
+ return self.__day.translate(self.num_trans_table) + separator + str(self.__month).translate(self.num_trans_table) + separator + self.__year.translate(self.num_trans_table)
@@ -0,0 +1,28 @@
1
+ from typing import Union
2
+ import datetime
3
+
4
+ # Import constants
5
+ from . constants import AR_NUMS
6
+
7
+
8
+ class Arabic_Time:
9
+ def __init__(self, time_object: Union[datetime.time, datetime.datetime]) -> None:
10
+ if not isinstance(time_object, datetime.time) and not isinstance(time_object, datetime.datetime):
11
+ raise TypeError(
12
+ f"Arabic_Time class error: The parameter passed to the instance is not a datetime.time object nor a datetime.datetime object.")
13
+
14
+ self.time_object = time_object
15
+
16
+ # string keys in translate table must be of length 1
17
+ self.num_trans_table = str.maketrans(AR_NUMS)
18
+
19
+ # convert first to `int` to turn 01 into 1
20
+ self.__hour = str(int(self.time_object.hour))
21
+ self.__minute = str(int(self.time_object.minute))
22
+ self.__second = str(int(self.time_object.second))
23
+
24
+ def time(self, separator: str = ":") -> str:
25
+ if not isinstance(separator, str):
26
+ raise TypeError(
27
+ f"Arabic_Date class error: The 'separator' parameter passed to the class method '{self.time.__name__}' is not a string.")
28
+ return self.__hour.translate(self.num_trans_table) + separator + self.__minute.translate(self.num_trans_table) + separator + self.__second.translate(self.num_trans_table)
@@ -0,0 +1,183 @@
1
+ # Constants
2
+ AR_NUMS = {
3
+ "0": "٠",
4
+ "1": "١",
5
+ "2": "٢",
6
+ "3": "٣",
7
+ "4": "٤",
8
+ "5": "٥",
9
+ "6": "٦",
10
+ "7": "٧",
11
+ "8": "٨",
12
+ "9": "٩"
13
+ }
14
+
15
+ ALL_COUNTRY_CODES = [
16
+ "DZ",
17
+ "BH",
18
+ "KM",
19
+ "DJ",
20
+ "EG",
21
+ "IQ",
22
+ "JO",
23
+ "KW",
24
+ "LB",
25
+ "LY",
26
+ "MR",
27
+ "MA",
28
+ "OM",
29
+ "PS",
30
+ "QA",
31
+ "SA",
32
+ "SO",
33
+ "SD",
34
+ "SY",
35
+ "TN",
36
+ "AE",
37
+ "YE"
38
+ ]
39
+
40
+ MONTH_GROUPS = {
41
+ "syriac": {
42
+ "east_nums": True,
43
+ "months": [
44
+ "كانون الثاني",
45
+ "شباط",
46
+ "آذار",
47
+ "نيسان",
48
+ "أيار",
49
+ "حزيران",
50
+ "تموز",
51
+ "آب",
52
+ "أيلول",
53
+ "تشرين الأول",
54
+ "تشرين الثاني",
55
+ "كانون الأول"
56
+ ],
57
+ "countries": [
58
+ "IQ",
59
+ "JO",
60
+ "LB",
61
+ "PS",
62
+ "SO",
63
+ "SY",
64
+ ],
65
+ },
66
+
67
+ "roman1": {
68
+ "east_nums": True,
69
+ "months": [
70
+ "يناير",
71
+ "فبراير",
72
+ "مارس",
73
+ "أبريل",
74
+ "مايو",
75
+ "يونيو",
76
+ "يوليو",
77
+ "أغسطس",
78
+ "سبتمبر",
79
+ "أكتوبر",
80
+ "نوفمبر",
81
+ "ديسمبر",
82
+ ],
83
+ "countries": [
84
+ "BH",
85
+ "KM",
86
+ "DJ",
87
+ "EG",
88
+ "KW",
89
+ "LY",
90
+ "OM",
91
+ "QA",
92
+ "SA",
93
+ "SO",
94
+ "SD",
95
+ "AE",
96
+ "YE",
97
+ ],
98
+ },
99
+ "roman2": {
100
+ "east_nums": False,
101
+ "months": [
102
+ "يناير",
103
+ "فبراير",
104
+ "مارس",
105
+ "أبريل",
106
+ "ماي",
107
+ "يونيو",
108
+ "يوليوز",
109
+ "غشت",
110
+ "شتنبر",
111
+ "أكتوبر",
112
+ "نونبر",
113
+ "دجنبر",
114
+ ],
115
+ "countries": [
116
+ "MA",
117
+ "MR",
118
+ ]
119
+ },
120
+
121
+ "french": {
122
+ "east_nums": False,
123
+ "months": [
124
+ "جانفي",
125
+ "فيفري",
126
+ "مارس",
127
+ "أفريل",
128
+ "ماي",
129
+ "جوان",
130
+ "جويلية",
131
+ "أوت",
132
+ "سبتمبر",
133
+ "أكتوبر",
134
+ "نوفمبر",
135
+ "ديسمبر",
136
+ ],
137
+ "countries": [
138
+ "DZ",
139
+ "TN",
140
+ ]
141
+ },
142
+ }
143
+
144
+
145
+ COUNTRY_CODES_DICT = {
146
+ "DZ": "Algeria",
147
+ "BH": "Bahrain",
148
+ "KM": "Comoros",
149
+ "DJ": "Djibouti",
150
+ "EG": "Egypt",
151
+ "IQ": "Iraq",
152
+ "JO": "Jordan",
153
+ "KW": "Kuwait",
154
+ "LB": "Lebanon",
155
+ "LY": "Libya",
156
+ "MR": "Mauritania",
157
+ "MA": "Morocco",
158
+ "OM": "Oman",
159
+ "PS": "Palestine",
160
+ "QA": "Qatar",
161
+ "SA": "Saudi Arabia",
162
+ "SO": "Somalia",
163
+ "SD": "Sudan",
164
+ "SY": "Syria",
165
+ "TN": "Tunisia",
166
+ "AE": "United Arab Emirates",
167
+ "YE": "Yemen"
168
+ }
169
+
170
+ DUAL_MONTHS = {
171
+ "1": "كانون الثاني (يناير)",
172
+ "2": "شباط (فبراير)",
173
+ "3": "آذار (مارس)",
174
+ "4": "نيسان (أبريل)",
175
+ "5": "أيار (مايو)",
176
+ "6": "حزيران (يونيو)",
177
+ "7": "تموز (يوليو)",
178
+ "8": "آب (أغسطس)",
179
+ "9": "أيلول (سبتمبر)",
180
+ "10": "تشرين الأول (أكتوبر)",
181
+ "11": "تشرين الثاني (نوفمبر)",
182
+ "12": "كانون الأول (ديسمبر)"
183
+ }
@@ -0,0 +1,21 @@
1
+ MIT Lincense
2
+
3
+ Copyright (c) 2024 Khaled Auwad
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,6 @@
1
+ Metadata-Version: 2.1
2
+ Name: arabic_datetime
3
+ Version: 0.0.0
4
+ Requires-Python: >=3.7
5
+ License-File: LICENSE
6
+
@@ -0,0 +1,9 @@
1
+ arabic_datetime/__init__.py,sha256=K5kZDLNbWdcQMrljULGfeoOnrRJH-L6xPF4sv6J145o,78
2
+ arabic_datetime/arabic_date.py,sha256=2auoWCcwkrBX5K1jNYuJjcJ7Kv6SloE7u5Gq8OxV8d4,8269
3
+ arabic_datetime/arabic_time.py,sha256=SjsYZx341zBqJ1EMQac4sDhNjcC9Z_ni9XwO9i-L-Vo,1324
4
+ arabic_datetime/constants.py,sha256=JxkRZV64NOTTR8CcJ5A6NLXbQhXhjiw_EYTpNw3MGJ8,3768
5
+ arabic_datetime-0.0.0.dist-info/LICENSE,sha256=6r7YXD-p9ftfmk3RtVngQYVpvzd1XEGih3OqAsFNphk,1091
6
+ arabic_datetime-0.0.0.dist-info/METADATA,sha256=T8oLzILAPLN_r3Dwf60qsmQxPa66NrA2mjPRb-POVC4,111
7
+ arabic_datetime-0.0.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
8
+ arabic_datetime-0.0.0.dist-info/top_level.txt,sha256=Zcet212wBPkc8e_qXsA-a0zd3hYM7s0ReY71BH_1dvg,16
9
+ arabic_datetime-0.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.43.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ arabic_datetime