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
@@ -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
- import warnings
11
-
12
- from nepali.timezone import NepaliTimeZone, utc_now
13
- from nepali.utils import to_nepali_timezone
14
-
15
- from ._converter import NepaliDateConverter
16
-
17
-
18
- class formater_class_mixin:
19
- def get_formater_class(self):
20
- return self.__class__.get_formater_class()
21
-
22
- @classmethod
23
- def get_formater_class(cls):
24
- if not hasattr(cls, '__formater_class__Cache'):
25
- from ._formarter import NepaliDateTimeFormater
26
- cls.__formater_class__Cache = NepaliDateTimeFormater
27
- return cls.__formater_class__Cache
28
-
29
- @classmethod
30
- def get_strptime_method(cls):
31
- if not hasattr(cls, '_strptime_method_CACHE'):
32
- from .parser import strptime
33
- cls._strptime_method_CACHE = strptime
34
- return cls._strptime_method_CACHE
35
-
36
- class nepalidate(formater_class_mixin):
37
- def __init__(self, year, month, day) -> None:
38
- self.__year = year
39
- self.__month = month
40
- self.__day = day
41
-
42
- # converting to english date
43
- year_en, month_en, day_en = NepaliDateConverter.nepali_to_english(year, month, day)
44
- self.__python_date = pythonDateTime.date(year_en, month_en, day_en)
45
-
46
- def __str__(self):
47
- return self.strftime_en('%Y-%m-%d')
48
-
49
- def __repr__(self):
50
- return "<nepalidate> "+str(self)
51
-
52
- def to_datetime(self):
53
- return pythonDateTime.datetime.combine(self.__python_date, pythonDateTime.time(), tzinfo=NepaliTimeZone())
54
-
55
- def to_date(self):
56
- return self.__python_date
57
-
58
- def to_nepalidatetime(self):
59
- return nepalidatetime.from_nepali_date(self)
60
-
61
- def to_nepali_datetime(self):
62
- warnings.warn(
63
- message="nepalidate.to_nepali_datetime is depreciated and no longer be available in version >= 1.0.0, use nepalidate.to_nepalidatetime instead.",
64
- category=DeprecationWarning
65
- )
66
- return self.to_nepalidatetime()
67
-
68
- def strftime(self, format):
69
- NepaliDateTimeFormater = self.get_formater_class()
70
- formater = NepaliDateTimeFormater(self)
71
- return formater.get_str(format)
72
-
73
- def strftime_en(self, format):
74
- NepaliDateTimeFormater = self.get_formater_class()
75
- formater = NepaliDateTimeFormater(self, english=True)
76
- return formater.get_str(format)
77
-
78
-
79
- # operators overloading
80
- # TODO: add more operators overloading
81
- def __eq__(self, other):
82
- """ equal """
83
-
84
- if type(other) == self.__class__:
85
- """
86
- NepaliDate object
87
- """
88
- return self.to_date() == other.to_date()
89
-
90
- elif type(other) == pythonDateTime.date:
91
- """
92
- pythonDate object
93
- """
94
- return self.to_date() == to_nepali_timezone(other)
95
-
96
- return False
97
-
98
- # static methods
99
- @classmethod
100
- def strptime(cls, datetime_str, format):
101
- nepalidatetime_strptime = cls.get_strptime_method()
102
- return nepalidatetime_strptime(datetime_str, format=format).date()
103
-
104
- @staticmethod
105
- def now(*args, **kwargs):
106
- return nepalidate.today()
107
-
108
- @staticmethod
109
- def today():
110
- year, month, day = NepaliDateConverter.current_nepali_date()
111
- return nepalidate(year, month, day)
112
-
113
- @staticmethod
114
- def from_datetime(datetime_object):
115
- return nepalidate.from_date(datetime_object.date())
116
-
117
- @staticmethod
118
- def from_date(date_object):
119
- npDate = nepalidate(*NepaliDateConverter.english_to_nepali(date_object.year, date_object.month, date_object.day))
120
- return npDate
121
-
122
- @staticmethod
123
- def from_nepalidatetime(datetime_object):
124
- return datetime_object.date()
125
-
126
- # property
127
-
128
- def weekday(self):
129
- '''
130
- Sunday => 0, Saturday => 6
131
- '''
132
- return (self.__python_date.weekday() + 1) % 7
133
- return self.__python_date.weekday()
134
-
135
- # nepali date properties
136
- @property
137
- def year(self):
138
- return self.__year
139
-
140
- @property
141
- def month(self):
142
- return self.__month
143
-
144
- @property
145
- def day(self):
146
- return self.__day
147
-
148
- @property
149
- def week_day(self):
150
- warnings.warn(
151
- message="nepalidate.week_day field is depreciated and no longer be available in version >= 1.0.0, use nepalidate.weekday() method instead.",
152
- category=DeprecationWarning
153
- )
154
- return self.weekday()
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
- def __repr__(self):
159
- return "<nepalitime> "+str(self)
276
+ elif type(other) == pythonDateTime.timedelta:
277
+ # timedelta object
278
+ return nepalidatetime.from_datetime(self.to_datetime() - other)
160
279
 
161
- # static methods
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
- class nepalidatetime(formater_class_mixin):
170
- """
171
- nepalidatetime
172
- """
288
+ elif type(other) == pythonDateTime.datetime:
289
+ # python datetime object
290
+ return self.to_datetime() < to_nepali_timezone(other)
173
291
 
174
- def __init__(self, year, month, day, hour=0, minute=0, second=0, microsecond=0):
175
- self.__npDate = nepalidate(year, month, day)
176
- self.__npTime = nepalitime(hour, minute, second, microsecond)
292
+ return NotImplemented
177
293
 
178
- def __str__(self):
179
- return str(self.__npDate)+' '+str(self.__npTime)
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
- def __repr__(self):
182
- return "<nepalidatetime> "+str(self)
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
- # operator overloadings
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
- def __add__(self, other):
188
- """ addition """
312
+ elif type(other) == pythonDateTime.datetime:
313
+ # python datetime object
314
+ return self.to_datetime() == to_nepali_timezone(other)
189
315
 
190
- if type(other) == pythonDateTime.timedelta:
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
- return None
324
+ elif type(other) == pythonDateTime.datetime:
325
+ # python datetime object
326
+ return self.to_datetime() != to_nepali_timezone(other)
198
327
 
199
- def __sub__(self, other):
200
- """ substraction """
328
+ return True
201
329
 
202
- if type(other) == self.__class__:
203
- """
204
- nepalidatetime object
205
- """
206
- return self.to_datetime() - other.to_datetime()
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
- elif type(other) == pythonDateTime.datetime:
209
- return self.to_datetime() - to_nepali_timezone(other)
336
+ elif type(other) == pythonDateTime.datetime:
337
+ # python datetime object
338
+ return self.to_datetime() > to_nepali_timezone(other)
210
339
 
211
- elif type(other) == pythonDateTime.timedelta:
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
- return None
348
+ elif type(other) == pythonDateTime.datetime:
349
+ # python datetime object
350
+ return self.to_datetime() >= to_nepali_timezone(other)
219
351
 
220
- def __lt__(self, other):
221
- """ less than """
352
+ return NotImplemented
222
353
 
223
- if type(other) == self.__class__:
224
- """
225
- nepalidatetime object
226
- """
227
- return self.to_datetime() < other.to_datetime()
354
+ # object transformation
228
355
 
229
- elif type(other) == pythonDateTime.datetime:
230
- """
231
- pythonDateTime object
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
- return None
364
+ def date(self):
365
+ return self.__np_date
366
+
367
+ def time(self):
368
+ return self.__np_time
237
369
 
238
- def __le__(self, other):
239
- """ less than equal """
370
+ # static methods
240
371
 
241
- if type(other) == self.__class__:
242
- """
243
- nepalidatetime object
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
- elif type(other) == pythonDateTime.datetime:
248
- """
249
- pythonDateTime object
250
- """
251
- return self.to_datetime() <= to_nepali_timezone(other)
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
- return None
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
- def __eq__(self, other):
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
- elif type(other) == pythonDateTime.datetime:
266
- """
267
- pythonDateTime object
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
- def __ne__(self, other):
275
- """ not equal """
410
+ @property
411
+ def day(self):
412
+ return self.__np_date.day
276
413
 
277
- if type(other) == self.__class__:
278
- """
279
- nepalidatetime object
280
- """
281
- return self.to_datetime() != other.to_datetime()
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
- elif type(other) == pythonDateTime.datetime:
284
- """
285
- pythonDateTime object
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