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.
- nepali/__init__.py +1 -1
- nepali/char.py +102 -81
- nepali/constants.py +66 -0
- nepali/date_converter.py +334 -0
- nepali/datetime/__init__.py +13 -14
- nepali/datetime/_datetime.py +391 -402
- nepali/datetime/_formatter.py +325 -0
- nepali/datetime/_humanize.py +117 -132
- nepali/datetime/_nepalimonth.py +118 -0
- nepali/datetime/_nepaliweek.py +125 -0
- nepali/datetime/parser/__init__.py +4 -4
- nepali/datetime/parser/_parser.py +59 -50
- nepali/datetime/parser/validators.py +249 -159
- nepali/datetime/utils.py +38 -0
- nepali/exceptions.py +8 -3
- nepali/locations/__init__.py +3 -0
- nepali/locations/_data.py +4271 -0
- nepali/locations/_locations.py +38 -0
- nepali/locations/models.py +104 -0
- nepali/locations/utils.py +54 -0
- nepali/number/__init__.py +19 -0
- nepali/number/_nepalinumber.py +563 -0
- nepali/number/_number.py +53 -0
- nepali/number/utils.py +72 -0
- nepali/phone_number.py +183 -0
- nepali/templatetags/__init__.py +0 -0
- nepali/templatetags/nepalidatetime.py +194 -24
- nepali/templatetags/nepalinumber.py +97 -7
- nepali/tests/test_date_converter.py +148 -0
- nepali/tests/test_datetime.py +275 -29
- nepali/tests/test_humanize.py +78 -7
- nepali/tests/test_locations.py +154 -0
- nepali/tests/test_nepalimonth.py +152 -0
- nepali/tests/test_nepaliweek.py +154 -0
- nepali/tests/test_number.py +3152 -0
- nepali/tests/test_parser.py +82 -69
- nepali/tests/test_phone_number.py +254 -0
- nepali/tests/test_timezone.py +192 -0
- nepali/timezone.py +50 -7
- nepali/utils.py +9 -68
- nepali-1.2.0.dist-info/METADATA +476 -0
- nepali-1.2.0.dist-info/RECORD +46 -0
- {nepali-0.5.5.dist-info → nepali-1.2.0.dist-info}/WHEEL +1 -1
- {nepali-0.5.5.dist-info → nepali-1.2.0.dist-info/licenses}/LICENSE +1 -1
- {nepali-0.5.5.dist-info → nepali-1.2.0.dist-info}/top_level.txt +0 -0
- nepali/datetime/_converter.py +0 -394
- nepali/datetime/_formarter.py +0 -314
- nepali/datetime.py +0 -1169
- nepali/number.py +0 -51
- nepali-0.5.5.dist-info/METADATA +0 -220
- nepali-0.5.5.dist-info/RECORD +0 -27
nepali/datetime/_datetime.py
CHANGED
|
@@ -1,441 +1,430 @@
|
|
|
1
|
-
#
|
|
2
|
-
#
|
|
3
|
-
# Author : Ajesh Sen Thapa
|
|
4
|
-
# Website: www.ajesh.com.np
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
|
|
8
|
-
import time
|
|
9
1
|
import datetime as pythonDateTime
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
from nepali.timezone import NepaliTimeZone, utc_now
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
2
|
+
|
|
3
|
+
from nepali.date_converter import converter as nepali_date_converter
|
|
4
|
+
from nepali.timezone import NepaliTimeZone, to_nepali_timezone, utc_now
|
|
5
|
+
|
|
6
|
+
from ._nepalimonth import nepalimonth
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class formatter_class_mixin:
|
|
10
|
+
"""
|
|
11
|
+
mixin for date time formatter.
|
|
12
|
+
adds methods `strftime(format)`
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
def get_formatter_class(self):
|
|
16
|
+
return self.__class__.init_formatter_class()
|
|
17
|
+
|
|
18
|
+
@classmethod
|
|
19
|
+
def init_formatter_class(cls):
|
|
20
|
+
if not hasattr(cls, "_formatter_class_cache"):
|
|
21
|
+
from ._formatter import NepaliDateTimeFormatter
|
|
22
|
+
|
|
23
|
+
cls._formatter_class_cache = NepaliDateTimeFormatter
|
|
24
|
+
return cls._formatter_class_cache
|
|
25
|
+
|
|
26
|
+
@classmethod
|
|
27
|
+
def get_strptime_method(cls):
|
|
28
|
+
if not hasattr(cls, "_strptime_method_cache"):
|
|
29
|
+
from .parser import strptime
|
|
30
|
+
|
|
31
|
+
cls._strptime_method_cache = strptime
|
|
32
|
+
return cls._strptime_method_cache
|
|
33
|
+
|
|
34
|
+
def strftime(self, format: str) -> str:
|
|
35
|
+
return self.strftime_en(format)
|
|
36
|
+
|
|
37
|
+
def strftime_en(self, format: str) -> str:
|
|
38
|
+
nepali_datetime_formatter = self.get_formatter_class()
|
|
39
|
+
formatter = nepali_datetime_formatter(self, devanagari=False)
|
|
40
|
+
return formatter.get_str(format)
|
|
41
|
+
|
|
42
|
+
def strftime_ne(self, format: str) -> str:
|
|
43
|
+
nepali_datetime_formatter = self.get_formatter_class()
|
|
44
|
+
formatter = nepali_datetime_formatter(self, devanagari=True)
|
|
45
|
+
return formatter.get_str(format)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class nepalidate(formatter_class_mixin):
|
|
49
|
+
def __init__(self, year, month, day) -> None:
|
|
50
|
+
if isinstance(month, nepalimonth):
|
|
51
|
+
month = month.value
|
|
52
|
+
|
|
53
|
+
self.__year = year
|
|
54
|
+
self.__month = month
|
|
55
|
+
self.__day = day
|
|
56
|
+
|
|
57
|
+
# converting to english date
|
|
58
|
+
year_en, month_en, day_en = nepali_date_converter.nepali_to_english(
|
|
59
|
+
year, month, day
|
|
60
|
+
)
|
|
61
|
+
self.__python_date = pythonDateTime.date(year_en, month_en, day_en)
|
|
62
|
+
|
|
63
|
+
def __str__(self):
|
|
64
|
+
return self.strftime_en("%Y-%m-%d")
|
|
65
|
+
|
|
66
|
+
def __repr__(self):
|
|
67
|
+
return f"<nepalidate> {self}"
|
|
68
|
+
|
|
69
|
+
def to_datetime(self):
|
|
70
|
+
return pythonDateTime.datetime.combine(
|
|
71
|
+
self.__python_date, pythonDateTime.time(), tzinfo=NepaliTimeZone()
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
def to_date(self):
|
|
75
|
+
return self.__python_date
|
|
76
|
+
|
|
77
|
+
def to_nepalidatetime(self):
|
|
78
|
+
return nepalidatetime.from_nepali_date(self)
|
|
79
|
+
|
|
80
|
+
# operators overloading
|
|
81
|
+
|
|
82
|
+
def __add__(self, other):
|
|
83
|
+
"""addition"""
|
|
84
|
+
if type(other) == pythonDateTime.timedelta:
|
|
85
|
+
# timedelta object
|
|
86
|
+
return nepalidate.from_date(self.to_date() + other)
|
|
87
|
+
return NotImplemented
|
|
88
|
+
|
|
89
|
+
def __sub__(self, other):
|
|
90
|
+
"""subtraction"""
|
|
91
|
+
if type(other) == self.__class__:
|
|
92
|
+
# nepalidate object
|
|
93
|
+
return self.to_date() - other.to_date()
|
|
94
|
+
|
|
95
|
+
elif type(other) == pythonDateTime.date:
|
|
96
|
+
# python date object
|
|
97
|
+
return self.to_date() - other
|
|
98
|
+
|
|
99
|
+
elif type(other) == pythonDateTime.timedelta:
|
|
100
|
+
# timedelta object
|
|
101
|
+
return nepalidate.from_date(self.to_date() - other)
|
|
102
|
+
|
|
103
|
+
return NotImplemented
|
|
104
|
+
|
|
105
|
+
def __lt__(self, other):
|
|
106
|
+
"""less than"""
|
|
107
|
+
if type(other) == self.__class__:
|
|
108
|
+
# nepalidatetime object
|
|
109
|
+
return self.to_date() < other.to_date()
|
|
110
|
+
|
|
111
|
+
elif type(other) == pythonDateTime.date:
|
|
112
|
+
# python date object
|
|
113
|
+
return self.to_date() < other
|
|
114
|
+
|
|
115
|
+
return NotImplemented
|
|
116
|
+
|
|
117
|
+
def __le__(self, other):
|
|
118
|
+
"""less than equal"""
|
|
119
|
+
if type(other) == self.__class__:
|
|
120
|
+
# nepalidate object
|
|
121
|
+
return self.to_date() <= other.to_date()
|
|
122
|
+
|
|
123
|
+
elif type(other) == pythonDateTime.date:
|
|
124
|
+
# python date object
|
|
125
|
+
return self.to_date() <= other
|
|
126
|
+
|
|
127
|
+
return NotImplemented
|
|
128
|
+
|
|
129
|
+
def __eq__(self, other):
|
|
130
|
+
"""equal"""
|
|
131
|
+
if type(other) == self.__class__:
|
|
132
|
+
# nepalidate object
|
|
133
|
+
return self.to_date() == other.to_date()
|
|
134
|
+
|
|
135
|
+
elif type(other) == pythonDateTime.date:
|
|
136
|
+
# python date object
|
|
137
|
+
return self.to_date() == other
|
|
138
|
+
|
|
139
|
+
return False
|
|
140
|
+
|
|
141
|
+
def __ne__(self, other):
|
|
142
|
+
"""not equal"""
|
|
143
|
+
if type(other) == self.__class__:
|
|
144
|
+
# nepalidate object
|
|
145
|
+
return self.to_date() != other.to_date()
|
|
146
|
+
|
|
147
|
+
elif type(other) == pythonDateTime.date:
|
|
148
|
+
# python date object
|
|
149
|
+
return self.to_date() != other
|
|
150
|
+
|
|
151
|
+
return True
|
|
152
|
+
|
|
153
|
+
def __gt__(self, other):
|
|
154
|
+
"""greater than"""
|
|
155
|
+
if type(other) == self.__class__:
|
|
156
|
+
# nepalidate object
|
|
157
|
+
return self.to_date() > other.to_date()
|
|
158
|
+
|
|
159
|
+
elif type(other) == pythonDateTime.date:
|
|
160
|
+
# python date object
|
|
161
|
+
return self.to_date() > other
|
|
162
|
+
|
|
163
|
+
return NotImplemented
|
|
164
|
+
|
|
165
|
+
def __ge__(self, other):
|
|
166
|
+
"""greater than equal"""
|
|
167
|
+
if type(other) == self.__class__:
|
|
168
|
+
# nepalidate object
|
|
169
|
+
return self.to_date() >= other.to_date()
|
|
170
|
+
|
|
171
|
+
elif type(other) == pythonDateTime.date:
|
|
172
|
+
# python date object
|
|
173
|
+
return self.to_date() >= other
|
|
174
|
+
|
|
175
|
+
return NotImplemented
|
|
176
|
+
|
|
177
|
+
# static methods
|
|
178
|
+
@classmethod
|
|
179
|
+
def strptime(cls, datetime_str, format):
|
|
180
|
+
nepalidatetime_strptime = cls.get_strptime_method()
|
|
181
|
+
return nepalidatetime_strptime(datetime_str, format=format).date()
|
|
182
|
+
|
|
183
|
+
@staticmethod
|
|
184
|
+
def now():
|
|
185
|
+
return nepalidate.today()
|
|
186
|
+
|
|
187
|
+
@staticmethod
|
|
188
|
+
def today():
|
|
189
|
+
return nepalidate.from_date(pythonDateTime.date.today())
|
|
190
|
+
|
|
191
|
+
@staticmethod
|
|
192
|
+
def from_datetime(datetime_object):
|
|
193
|
+
return nepalidate.from_date(datetime_object.date())
|
|
194
|
+
|
|
195
|
+
@staticmethod
|
|
196
|
+
def from_date(date_object):
|
|
197
|
+
return nepalidate(
|
|
198
|
+
*nepali_date_converter.english_to_nepali(
|
|
199
|
+
date_object.year, date_object.month, date_object.day
|
|
200
|
+
)
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
@staticmethod
|
|
204
|
+
def from_nepalidatetime(datetime_object):
|
|
205
|
+
return datetime_object.date()
|
|
206
|
+
|
|
207
|
+
# property
|
|
208
|
+
|
|
209
|
+
def weekday(self):
|
|
210
|
+
"""
|
|
211
|
+
Sunday => 0, Saturday => 6
|
|
212
|
+
"""
|
|
213
|
+
return (self.__python_date.weekday() + 1) % 7
|
|
214
|
+
|
|
215
|
+
# nepali date properties
|
|
216
|
+
@property
|
|
217
|
+
def year(self):
|
|
218
|
+
return self.__year
|
|
219
|
+
|
|
220
|
+
@property
|
|
221
|
+
def month(self):
|
|
222
|
+
return self.__month
|
|
223
|
+
|
|
224
|
+
@property
|
|
225
|
+
def day(self):
|
|
226
|
+
return self.__day
|
|
227
|
+
|
|
155
228
|
|
|
156
229
|
class nepalitime(pythonDateTime.time):
|
|
230
|
+
def __repr__(self):
|
|
231
|
+
return f"<nepalitime> {self}"
|
|
232
|
+
|
|
233
|
+
# static methods
|
|
234
|
+
|
|
235
|
+
@staticmethod
|
|
236
|
+
def now():
|
|
237
|
+
dt_now = pythonDateTime.datetime.now()
|
|
238
|
+
return nepalitime(dt_now.hour, dt_now.minute, dt_now.second, dt_now.microsecond)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
class nepalidatetime(formatter_class_mixin):
|
|
242
|
+
"""
|
|
243
|
+
nepalidatetime
|
|
244
|
+
"""
|
|
245
|
+
|
|
246
|
+
def __init__(self, year, month, day, hour=0, minute=0, second=0, microsecond=0):
|
|
247
|
+
self.__np_date = nepalidate(year, month, day)
|
|
248
|
+
self.__np_time = nepalitime(hour, minute, second, microsecond)
|
|
249
|
+
|
|
250
|
+
def __str__(self):
|
|
251
|
+
return f"{self.__np_date} {self.__np_time}"
|
|
252
|
+
|
|
253
|
+
def __repr__(self):
|
|
254
|
+
return f"<nepalidatetime> {self}"
|
|
255
|
+
|
|
256
|
+
# operator overloading
|
|
257
|
+
|
|
258
|
+
def __add__(self, other):
|
|
259
|
+
"""addition"""
|
|
260
|
+
if type(other) == pythonDateTime.timedelta:
|
|
261
|
+
# timedelta object
|
|
262
|
+
return nepalidatetime.from_datetime(self.to_datetime() + other)
|
|
263
|
+
|
|
264
|
+
return NotImplemented
|
|
265
|
+
|
|
266
|
+
def __sub__(self, other):
|
|
267
|
+
"""subtraction"""
|
|
268
|
+
if type(other) == self.__class__:
|
|
269
|
+
# nepalidatetime object
|
|
270
|
+
return self.to_datetime() - other.to_datetime()
|
|
271
|
+
|
|
272
|
+
elif type(other) == pythonDateTime.datetime:
|
|
273
|
+
# python datetime object
|
|
274
|
+
return self.to_datetime() - to_nepali_timezone(other)
|
|
157
275
|
|
|
158
|
-
|
|
159
|
-
|
|
276
|
+
elif type(other) == pythonDateTime.timedelta:
|
|
277
|
+
# timedelta object
|
|
278
|
+
return nepalidatetime.from_datetime(self.to_datetime() - other)
|
|
160
279
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
@staticmethod
|
|
164
|
-
def now(*args, **kwargs):
|
|
165
|
-
dt_now = pythonDateTime.datetime.now()
|
|
166
|
-
return nepalitime(dt_now.hour, dt_now.minute, dt_now.second, dt_now.microsecond)
|
|
280
|
+
return NotImplemented
|
|
167
281
|
|
|
282
|
+
def __lt__(self, other):
|
|
283
|
+
"""less than"""
|
|
284
|
+
if type(other) == self.__class__:
|
|
285
|
+
# nepalidatetime object
|
|
286
|
+
return self.to_datetime() < other.to_datetime()
|
|
168
287
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
"""
|
|
288
|
+
elif type(other) == pythonDateTime.datetime:
|
|
289
|
+
# python datetime object
|
|
290
|
+
return self.to_datetime() < to_nepali_timezone(other)
|
|
173
291
|
|
|
174
|
-
|
|
175
|
-
self.__npDate = nepalidate(year, month, day)
|
|
176
|
-
self.__npTime = nepalitime(hour, minute, second, microsecond)
|
|
292
|
+
return NotImplemented
|
|
177
293
|
|
|
178
|
-
|
|
179
|
-
|
|
294
|
+
def __le__(self, other):
|
|
295
|
+
"""less than equal"""
|
|
296
|
+
if type(other) == self.__class__:
|
|
297
|
+
# nepalidatetime object
|
|
298
|
+
return self.to_datetime() <= other.to_datetime()
|
|
180
299
|
|
|
181
|
-
|
|
182
|
-
|
|
300
|
+
elif type(other) == pythonDateTime.datetime:
|
|
301
|
+
# python datetime object
|
|
302
|
+
return self.to_datetime() <= to_nepali_timezone(other)
|
|
183
303
|
|
|
304
|
+
return NotImplemented
|
|
184
305
|
|
|
185
|
-
|
|
306
|
+
def __eq__(self, other):
|
|
307
|
+
"""equal"""
|
|
308
|
+
if type(other) == self.__class__:
|
|
309
|
+
# nepalidatetime object
|
|
310
|
+
return self.to_datetime() == other.to_datetime()
|
|
186
311
|
|
|
187
|
-
|
|
188
|
-
|
|
312
|
+
elif type(other) == pythonDateTime.datetime:
|
|
313
|
+
# python datetime object
|
|
314
|
+
return self.to_datetime() == to_nepali_timezone(other)
|
|
189
315
|
|
|
190
|
-
|
|
191
|
-
"""
|
|
192
|
-
timedelta object
|
|
193
|
-
"""
|
|
194
|
-
return nepalidatetime.from_datetime(self.to_datetime() + other)
|
|
316
|
+
return False
|
|
195
317
|
|
|
318
|
+
def __ne__(self, other):
|
|
319
|
+
"""not equal"""
|
|
320
|
+
if type(other) == self.__class__:
|
|
321
|
+
# nepalidatetime object
|
|
322
|
+
return self.to_datetime() != other.to_datetime()
|
|
196
323
|
|
|
197
|
-
|
|
324
|
+
elif type(other) == pythonDateTime.datetime:
|
|
325
|
+
# python datetime object
|
|
326
|
+
return self.to_datetime() != to_nepali_timezone(other)
|
|
198
327
|
|
|
199
|
-
|
|
200
|
-
""" substraction """
|
|
328
|
+
return True
|
|
201
329
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
330
|
+
def __gt__(self, other):
|
|
331
|
+
"""greater than"""
|
|
332
|
+
if type(other) == self.__class__:
|
|
333
|
+
# nepalidatetime object
|
|
334
|
+
return self.to_datetime() > other.to_datetime()
|
|
207
335
|
|
|
208
|
-
|
|
209
|
-
|
|
336
|
+
elif type(other) == pythonDateTime.datetime:
|
|
337
|
+
# python datetime object
|
|
338
|
+
return self.to_datetime() > to_nepali_timezone(other)
|
|
210
339
|
|
|
211
|
-
|
|
212
|
-
"""
|
|
213
|
-
timedelta object
|
|
214
|
-
"""
|
|
215
|
-
return nepalidatetime.from_datetime(self.to_datetime() - other)
|
|
340
|
+
return NotImplemented
|
|
216
341
|
|
|
342
|
+
def __ge__(self, other):
|
|
343
|
+
"""greater than equal"""
|
|
344
|
+
if type(other) == self.__class__:
|
|
345
|
+
# nepalidatetime object
|
|
346
|
+
return self.to_datetime() >= other.to_datetime()
|
|
217
347
|
|
|
218
|
-
|
|
348
|
+
elif type(other) == pythonDateTime.datetime:
|
|
349
|
+
# python datetime object
|
|
350
|
+
return self.to_datetime() >= to_nepali_timezone(other)
|
|
219
351
|
|
|
220
|
-
|
|
221
|
-
""" less than """
|
|
352
|
+
return NotImplemented
|
|
222
353
|
|
|
223
|
-
|
|
224
|
-
"""
|
|
225
|
-
nepalidatetime object
|
|
226
|
-
"""
|
|
227
|
-
return self.to_datetime() < other.to_datetime()
|
|
354
|
+
# object transformation
|
|
228
355
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
return self.to_datetime() < to_nepali_timezone(other)
|
|
356
|
+
def to_datetime(self):
|
|
357
|
+
return pythonDateTime.datetime.combine(
|
|
358
|
+
self.__np_date.to_date(), self.__np_time, tzinfo=NepaliTimeZone()
|
|
359
|
+
)
|
|
234
360
|
|
|
361
|
+
def to_date(self):
|
|
362
|
+
return self.to_datetime().date()
|
|
235
363
|
|
|
236
|
-
|
|
364
|
+
def date(self):
|
|
365
|
+
return self.__np_date
|
|
366
|
+
|
|
367
|
+
def time(self):
|
|
368
|
+
return self.__np_time
|
|
237
369
|
|
|
238
|
-
|
|
239
|
-
""" less than equal """
|
|
370
|
+
# static methods
|
|
240
371
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
return self.to_datetime() <= other.to_datetime()
|
|
372
|
+
@classmethod
|
|
373
|
+
def strptime(cls, datetime_str, format):
|
|
374
|
+
nepalidatetime_strptime = cls.get_strptime_method()
|
|
375
|
+
return nepalidatetime_strptime(datetime_str, format=format)
|
|
246
376
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
377
|
+
@staticmethod
|
|
378
|
+
def from_datetime(dt):
|
|
379
|
+
dt = to_nepali_timezone(dt)
|
|
380
|
+
nd = nepalidate.from_date(dt.date())
|
|
381
|
+
return nepalidatetime(
|
|
382
|
+
nd.year, nd.month, nd.day, dt.hour, dt.minute, dt.second, dt.microsecond
|
|
383
|
+
)
|
|
252
384
|
|
|
385
|
+
@staticmethod
|
|
386
|
+
def from_date(date_object):
|
|
387
|
+
nepali_date_object = nepalidate.from_date(date_object)
|
|
388
|
+
return nepalidatetime.from_nepali_date(nepali_date_object)
|
|
253
389
|
|
|
254
|
-
|
|
390
|
+
@staticmethod
|
|
391
|
+
def from_nepali_date(nepali_date_object):
|
|
392
|
+
return nepalidatetime(
|
|
393
|
+
nepali_date_object.year, nepali_date_object.month, nepali_date_object.day
|
|
394
|
+
)
|
|
395
|
+
|
|
396
|
+
@staticmethod
|
|
397
|
+
def now():
|
|
398
|
+
return nepalidatetime.from_datetime(utc_now())
|
|
255
399
|
|
|
256
|
-
|
|
257
|
-
""" equal """
|
|
258
|
-
|
|
259
|
-
if type(other) == self.__class__:
|
|
260
|
-
"""
|
|
261
|
-
nepalidatetime object
|
|
262
|
-
"""
|
|
263
|
-
return self.to_datetime() == other.to_datetime()
|
|
400
|
+
# property
|
|
264
401
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
"""
|
|
269
|
-
return self.to_datetime() == to_nepali_timezone(other)
|
|
270
|
-
|
|
271
|
-
return False
|
|
402
|
+
@property
|
|
403
|
+
def year(self):
|
|
404
|
+
return self.__np_date.year
|
|
272
405
|
|
|
406
|
+
@property
|
|
407
|
+
def month(self):
|
|
408
|
+
return self.__np_date.month
|
|
273
409
|
|
|
274
|
-
|
|
275
|
-
|
|
410
|
+
@property
|
|
411
|
+
def day(self):
|
|
412
|
+
return self.__np_date.day
|
|
276
413
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
414
|
+
def weekday(self):
|
|
415
|
+
"""
|
|
416
|
+
Sunday => 0, Saturday => 6
|
|
417
|
+
"""
|
|
418
|
+
return self.__np_date.weekday()
|
|
419
|
+
|
|
420
|
+
@property
|
|
421
|
+
def hour(self):
|
|
422
|
+
return self.__np_time.hour
|
|
282
423
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
"""
|
|
287
|
-
return self.to_datetime() != to_nepali_timezone(other)
|
|
288
|
-
|
|
289
|
-
return True
|
|
290
|
-
|
|
291
|
-
def __gt__(self, other):
|
|
292
|
-
""" greater than """
|
|
293
|
-
|
|
294
|
-
if type(other) == self.__class__:
|
|
295
|
-
"""
|
|
296
|
-
nepalidatetime object
|
|
297
|
-
"""
|
|
298
|
-
return self.to_datetime() > other.to_datetime()
|
|
299
|
-
|
|
300
|
-
elif type(other) == pythonDateTime.datetime:
|
|
301
|
-
"""
|
|
302
|
-
pythonDateTime object
|
|
303
|
-
"""
|
|
304
|
-
return self.to_datetime() > to_nepali_timezone(other)
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
return None
|
|
308
|
-
|
|
309
|
-
def __ge__(self, other):
|
|
310
|
-
""" greater than equal """
|
|
311
|
-
|
|
312
|
-
if type(other) == self.__class__:
|
|
313
|
-
"""
|
|
314
|
-
nepalidatetime object
|
|
315
|
-
"""
|
|
316
|
-
return self.to_datetime() >= other.to_datetime()
|
|
317
|
-
|
|
318
|
-
elif type(other) == pythonDateTime.datetime:
|
|
319
|
-
"""
|
|
320
|
-
pythonDateTime object
|
|
321
|
-
"""
|
|
322
|
-
return self.to_datetime() >= to_nepali_timezone(other)
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
return None
|
|
326
|
-
|
|
327
|
-
# object transformation
|
|
328
|
-
def to_datetime(self):
|
|
329
|
-
return pythonDateTime.datetime.combine(self.__npDate.to_date(), self.__npTime, tzinfo=NepaliTimeZone())
|
|
330
|
-
|
|
331
|
-
def to_date(self):
|
|
332
|
-
return self.to_datetime().date()
|
|
333
|
-
|
|
334
|
-
def date(self):
|
|
335
|
-
return self.__npDate
|
|
336
|
-
|
|
337
|
-
def time(self):
|
|
338
|
-
return self.__npTime
|
|
339
|
-
|
|
340
|
-
# string format
|
|
341
|
-
def strftime(self, format):
|
|
342
|
-
NepaliDateTimeFormater = self.get_formater_class()
|
|
343
|
-
formater = NepaliDateTimeFormater(self)
|
|
344
|
-
return formater.get_str(format)
|
|
345
|
-
|
|
346
|
-
def strftime_en(self, format):
|
|
347
|
-
NepaliDateTimeFormater = self.get_formater_class()
|
|
348
|
-
formater = NepaliDateTimeFormater(self, english=True)
|
|
349
|
-
return formater.get_str(format)
|
|
350
|
-
|
|
351
|
-
# static methods
|
|
352
|
-
|
|
353
|
-
@classmethod
|
|
354
|
-
def strptime(cls, datetime_str, format):
|
|
355
|
-
nepalidatetime_strptime = cls.get_strptime_method()
|
|
356
|
-
return nepalidatetime_strptime(datetime_str, format=format)
|
|
357
|
-
|
|
358
|
-
@staticmethod
|
|
359
|
-
def from_datetime(dt):
|
|
360
|
-
dt = to_nepali_timezone(dt)
|
|
361
|
-
nd = nepalidate.from_date(dt.date())
|
|
362
|
-
return nepalidatetime(nd.year, nd.month, nd.day, dt.hour, dt.minute, dt.second, dt.microsecond)
|
|
363
|
-
|
|
364
|
-
@staticmethod
|
|
365
|
-
def from_date(date_object):
|
|
366
|
-
nepali_date_object = nepalidate.from_date(date_object)
|
|
367
|
-
return nepalidatetime.from_nepali_date(nepali_date_object)
|
|
368
|
-
|
|
369
|
-
@staticmethod
|
|
370
|
-
def from_nepali_date(nepali_date_object):
|
|
371
|
-
return nepalidatetime(nepali_date_object.year, nepali_date_object.month, nepali_date_object.day)
|
|
372
|
-
|
|
373
|
-
@staticmethod
|
|
374
|
-
def now():
|
|
375
|
-
return nepalidatetime.from_datetime(utc_now())
|
|
376
|
-
|
|
377
|
-
# property
|
|
378
|
-
|
|
379
|
-
@property
|
|
380
|
-
def year(self):
|
|
381
|
-
return self.__npDate.year
|
|
382
|
-
|
|
383
|
-
@property
|
|
384
|
-
def month(self):
|
|
385
|
-
return self.__npDate.month
|
|
386
|
-
|
|
387
|
-
@property
|
|
388
|
-
def day(self):
|
|
389
|
-
return self.__npDate.day
|
|
390
|
-
|
|
391
|
-
def weekday(self):
|
|
392
|
-
'''
|
|
393
|
-
Sunday => 0, Saturday => 6
|
|
394
|
-
'''
|
|
395
|
-
return self.__npDate.weekday()
|
|
396
|
-
|
|
397
|
-
@property
|
|
398
|
-
def week_day(self):
|
|
399
|
-
warnings.warn(
|
|
400
|
-
message="nepalidate.week_day field is depreciated and no longer be available in version >= 1.0.0, use nepalidatetime.weekday() method instead.",
|
|
401
|
-
category=DeprecationWarning
|
|
402
|
-
)
|
|
403
|
-
return self.__npDate.weekday()
|
|
404
|
-
|
|
405
|
-
@property
|
|
406
|
-
def hour(self):
|
|
407
|
-
return self.__npTime.hour
|
|
408
|
-
|
|
409
|
-
@property
|
|
410
|
-
def minute(self):
|
|
411
|
-
return self.__npTime.minute
|
|
412
|
-
|
|
413
|
-
@property
|
|
414
|
-
def second(self):
|
|
415
|
-
return self.__npTime.second
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
class NepaliDate(nepalidate):
|
|
419
|
-
def __init__(self, *args, **kwargs):
|
|
420
|
-
warnings.warn(
|
|
421
|
-
message="NepaliDate is depreciated and no longer be available in version >= 1.0.0, use nepalidate instead.",
|
|
422
|
-
category=DeprecationWarning
|
|
423
|
-
)
|
|
424
|
-
super().__init__(*args, **kwargs)
|
|
425
|
-
|
|
426
|
-
class NepaliTime(nepalidate):
|
|
427
|
-
def __init__(self, *args, **kwargs):
|
|
428
|
-
warnings.warn(
|
|
429
|
-
message="NepaliTime is depreciated and no longer be available in version >= 1.0.0, use nepalitime instead.",
|
|
430
|
-
category=DeprecationWarning
|
|
431
|
-
)
|
|
432
|
-
super().__init__(*args, **kwargs)
|
|
433
|
-
|
|
434
|
-
class NepaliDateTime(nepalidate):
|
|
435
|
-
def __init__(self, *args, **kwargs):
|
|
436
|
-
warnings.warn(
|
|
437
|
-
message="NepaliDateTime is depreciated and no longer be available in version >= 1.0.0, use nepalidatetime instead.",
|
|
438
|
-
category=DeprecationWarning
|
|
439
|
-
)
|
|
440
|
-
super().__init__(*args, **kwargs)
|
|
424
|
+
@property
|
|
425
|
+
def minute(self):
|
|
426
|
+
return self.__np_time.minute
|
|
441
427
|
|
|
428
|
+
@property
|
|
429
|
+
def second(self):
|
|
430
|
+
return self.__np_time.second
|