nepali 1.0.0__tar.gz → 1.1.0__tar.gz
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.
Potentially problematic release.
This version of nepali might be problematic. Click here for more details.
- {nepali-1.0.0 → nepali-1.1.0}/PKG-INFO +14 -45
- {nepali-1.0.0 → nepali-1.1.0}/README.md +10 -44
- {nepali-1.0.0/nepali/datetime → nepali-1.1.0/nepali}/constants.py +15 -2
- {nepali-1.0.0 → nepali-1.1.0}/nepali/datetime/__init__.py +1 -1
- {nepali-1.0.0 → nepali-1.1.0}/nepali/datetime/_datetime.py +12 -13
- {nepali-1.0.0 → nepali-1.1.0}/nepali/datetime/_formatter.py +3 -2
- {nepali-1.0.0 → nepali-1.1.0}/nepali/datetime/_humanize.py +14 -29
- {nepali-1.0.0 → nepali-1.1.0}/nepali/datetime/_nepalimonth.py +7 -6
- {nepali-1.0.0 → nepali-1.1.0}/nepali/datetime/_nepaliweek.py +4 -3
- {nepali-1.0.0 → nepali-1.1.0}/nepali/datetime/parser/__init__.py +1 -1
- {nepali-1.0.0 → nepali-1.1.0}/nepali/datetime/parser/_parser.py +7 -9
- {nepali-1.0.0 → nepali-1.1.0}/nepali/datetime/parser/validators.py +162 -78
- {nepali-1.0.0 → nepali-1.1.0}/nepali/datetime/utils.py +1 -0
- nepali-1.1.0/nepali/locations/__init__.py +3 -0
- {nepali-1.0.0 → nepali-1.1.0}/nepali/locations/_locations.py +1 -1
- {nepali-1.0.0 → nepali-1.1.0}/nepali/locations/utils.py +1 -2
- {nepali-1.0.0 → nepali-1.1.0}/nepali/number/_nepalinumber.py +26 -12
- {nepali-1.0.0 → nepali-1.1.0}/nepali/number/_number.py +1 -6
- {nepali-1.0.0 → nepali-1.1.0}/nepali/number/utils.py +1 -2
- {nepali-1.0.0 → nepali-1.1.0}/nepali/phone_number.py +2 -3
- nepali-1.1.0/nepali/templatetags/nepalidatetime.py +201 -0
- nepali-1.1.0/nepali/templatetags/nepalinumber.py +103 -0
- {nepali-1.0.0 → nepali-1.1.0}/nepali/tests/test_datetime.py +3 -5
- {nepali-1.0.0 → nepali-1.1.0}/nepali/tests/test_humanize.py +1 -2
- {nepali-1.0.0 → nepali-1.1.0}/nepali/tests/test_number.py +35 -33
- {nepali-1.0.0 → nepali-1.1.0}/nepali/tests/test_timezone.py +6 -5
- {nepali-1.0.0 → nepali-1.1.0}/nepali/timezone.py +5 -3
- {nepali-1.0.0 → nepali-1.1.0}/nepali/utils.py +1 -1
- {nepali-1.0.0 → nepali-1.1.0}/nepali.egg-info/PKG-INFO +14 -45
- {nepali-1.0.0 → nepali-1.1.0}/nepali.egg-info/SOURCES.txt +1 -1
- {nepali-1.0.0 → nepali-1.1.0}/setup.py +12 -3
- nepali-1.0.0/nepali/locations/__init__.py +0 -3
- nepali-1.0.0/nepali/templatetags/nepalidatetime.py +0 -38
- nepali-1.0.0/nepali/templatetags/nepalinumber.py +0 -15
- {nepali-1.0.0 → nepali-1.1.0}/LICENSE +0 -0
- {nepali-1.0.0 → nepali-1.1.0}/nepali/__init__.py +0 -0
- {nepali-1.0.0 → nepali-1.1.0}/nepali/char.py +0 -0
- {nepali-1.0.0 → nepali-1.1.0}/nepali/date_converter.py +0 -0
- {nepali-1.0.0 → nepali-1.1.0}/nepali/exceptions.py +0 -0
- {nepali-1.0.0 → nepali-1.1.0}/nepali/locations/_data.py +0 -0
- {nepali-1.0.0 → nepali-1.1.0}/nepali/locations/models.py +0 -0
- {nepali-1.0.0 → nepali-1.1.0}/nepali/number/__init__.py +1 -1
- {nepali-1.0.0 → nepali-1.1.0}/nepali/templatetags/__init__.py +0 -0
- {nepali-1.0.0 → nepali-1.1.0}/nepali/tests/__init__.py +0 -0
- {nepali-1.0.0 → nepali-1.1.0}/nepali/tests/test_date_converter.py +0 -0
- {nepali-1.0.0 → nepali-1.1.0}/nepali/tests/test_locations.py +3 -3
- {nepali-1.0.0 → nepali-1.1.0}/nepali/tests/test_nepalimonth.py +0 -0
- {nepali-1.0.0 → nepali-1.1.0}/nepali/tests/test_nepaliweek.py +0 -0
- {nepali-1.0.0 → nepali-1.1.0}/nepali/tests/test_parser.py +0 -0
- {nepali-1.0.0 → nepali-1.1.0}/nepali/tests/test_phone_number.py +3 -3
- {nepali-1.0.0 → nepali-1.1.0}/nepali.egg-info/dependency_links.txt +0 -0
- {nepali-1.0.0 → nepali-1.1.0}/nepali.egg-info/top_level.txt +0 -0
- {nepali-1.0.0 → nepali-1.1.0}/setup.cfg +0 -0
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: nepali
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.1.0
|
|
4
4
|
Summary: nepalidatetime compatible with python's datetime feature. Converting nepali date to english, parsing nepali datetime, nepali timezone, and timedelta support in nepali datetime
|
|
5
5
|
Home-page: https://github.com/opensource-nepal/py-nepali
|
|
6
6
|
Author: opensource-nepal
|
|
7
7
|
Author-email: aj3sshh@gmail.com, sugatbajracharya49@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Source, https://github.com/opensource-nepal/py-nepali
|
|
10
|
+
Project-URL: Changelog, https://github.com/opensource-nepal/py-nepali/blob/main/CHANGELOG.md
|
|
8
11
|
Keywords: nepali date conversion,convert date,nepali date time,python convert date,parse nepali date time
|
|
9
12
|
Classifier: Programming Language :: Python :: 3
|
|
10
13
|
Classifier: License :: OSI Approved :: MIT License
|
|
@@ -15,9 +18,9 @@ License-File: LICENSE
|
|
|
15
18
|
# nepali
|
|
16
19
|
|
|
17
20
|
[](https://badge.fury.io/py/nepali)
|
|
18
|
-
[](https://github.com/opensource-nepal/py-nepali/actions)
|
|
19
22
|
[](https://pypi.org/project/nepali/)
|
|
20
|
-
[](https://codecov.io/gh/opensource-nepal/py-nepali)
|
|
21
24
|
|
|
22
25
|
`nepali` is a python package containing features that will be useful for Nepali projects.
|
|
23
26
|
|
|
@@ -63,10 +66,11 @@ phone_number.parse("+977-9845217789")
|
|
|
63
66
|
- [timezone](#timezone)
|
|
64
67
|
- [parse](#parse)
|
|
65
68
|
- [strftime() and strptime() Format Codes](#strftime-and-strptime-format-codes)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
1. [Numbers](#numbers)
|
|
70
|
+
- [nepalinumber](#nepalinumber)
|
|
71
|
+
1. [Phone Number](#phone-number)
|
|
72
|
+
1. [Locations](#locations)
|
|
73
|
+
1. [For Django Template](#for-django-template)
|
|
70
74
|
|
|
71
75
|
## Date and Time
|
|
72
76
|
|
|
@@ -310,7 +314,7 @@ np_datetime = parse("Jestha 15, 2079") # 2079-02-15 00:00:00
|
|
|
310
314
|
| `%A` | Weekday as locale’s full name. | Sunday, Monday, …, Saturday |
|
|
311
315
|
| `%d` | Day of the month as a zero-padded decimal number. | 01, 02, …, 31 |
|
|
312
316
|
| `%-d` | Day of the month as a decimal number. | 1, 2, …, 31 |
|
|
313
|
-
| `%B` | Month as locale’s full name. |
|
|
317
|
+
| `%B` | Month as locale’s full name. | Baishakh, Jestha, …, Chaitra |
|
|
314
318
|
| `%m` | Month as a zero-padded decimal number. | 01, 02, …, 12 |
|
|
315
319
|
| `%-m` | Month as a decimal number. | 1, 2, …, 12 |
|
|
316
320
|
| `%y` | Year without century as a zero-padded decimal number. | 00, 01, …, 99 |
|
|
@@ -446,44 +450,9 @@ get_municipality(name_nepali="विराटनगर")
|
|
|
446
450
|
|
|
447
451
|
---
|
|
448
452
|
|
|
449
|
-
## For Django
|
|
453
|
+
## For Django
|
|
450
454
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
```python
|
|
454
|
-
INSTALLED_APPS = [
|
|
455
|
-
...
|
|
456
|
-
'nepali',
|
|
457
|
-
...
|
|
458
|
-
]
|
|
459
|
-
```
|
|
460
|
-
|
|
461
|
-
In your Template
|
|
462
|
-
|
|
463
|
-
```python
|
|
464
|
-
{% load nepalidatetime %}
|
|
465
|
-
```
|
|
466
|
-
|
|
467
|
-
```python
|
|
468
|
-
{% nepalinow %}
|
|
469
|
-
```
|
|
470
|
-
|
|
471
|
-
```python
|
|
472
|
-
{% nepalinow '%Y-%m-%d' %}
|
|
473
|
-
```
|
|
474
|
-
|
|
475
|
-
```python
|
|
476
|
-
{{ datetimeobj|nepalidate:"%Y-%m-%d" }}
|
|
477
|
-
{{ datetimeobj|nepalidate_en:"%Y-%m-%d" }}
|
|
478
|
-
```
|
|
479
|
-
|
|
480
|
-
```python
|
|
481
|
-
{{ datetimeobj|nepalihumanize }}
|
|
482
|
-
```
|
|
483
|
-
|
|
484
|
-
```python
|
|
485
|
-
{{ forloop.counter|nepalinumber }}
|
|
486
|
-
```
|
|
455
|
+
We have created a new Django package called [django-nepali](https://github.com/opensource-nepal/django-nepali) to support `nepali` package. For more information, please visit [django-nepali](https://github.com/opensource-nepal/django-nepali).
|
|
487
456
|
|
|
488
457
|
## Contribution
|
|
489
458
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# nepali
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/py/nepali)
|
|
4
|
-
[](https://github.com/opensource-nepal/py-nepali/actions)
|
|
5
5
|
[](https://pypi.org/project/nepali/)
|
|
6
|
-
[](https://codecov.io/gh/opensource-nepal/py-nepali)
|
|
7
7
|
|
|
8
8
|
`nepali` is a python package containing features that will be useful for Nepali projects.
|
|
9
9
|
|
|
@@ -49,10 +49,11 @@ phone_number.parse("+977-9845217789")
|
|
|
49
49
|
- [timezone](#timezone)
|
|
50
50
|
- [parse](#parse)
|
|
51
51
|
- [strftime() and strptime() Format Codes](#strftime-and-strptime-format-codes)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
1. [Numbers](#numbers)
|
|
53
|
+
- [nepalinumber](#nepalinumber)
|
|
54
|
+
1. [Phone Number](#phone-number)
|
|
55
|
+
1. [Locations](#locations)
|
|
56
|
+
1. [For Django Template](#for-django-template)
|
|
56
57
|
|
|
57
58
|
## Date and Time
|
|
58
59
|
|
|
@@ -296,7 +297,7 @@ np_datetime = parse("Jestha 15, 2079") # 2079-02-15 00:00:00
|
|
|
296
297
|
| `%A` | Weekday as locale’s full name. | Sunday, Monday, …, Saturday |
|
|
297
298
|
| `%d` | Day of the month as a zero-padded decimal number. | 01, 02, …, 31 |
|
|
298
299
|
| `%-d` | Day of the month as a decimal number. | 1, 2, …, 31 |
|
|
299
|
-
| `%B` | Month as locale’s full name. |
|
|
300
|
+
| `%B` | Month as locale’s full name. | Baishakh, Jestha, …, Chaitra |
|
|
300
301
|
| `%m` | Month as a zero-padded decimal number. | 01, 02, …, 12 |
|
|
301
302
|
| `%-m` | Month as a decimal number. | 1, 2, …, 12 |
|
|
302
303
|
| `%y` | Year without century as a zero-padded decimal number. | 00, 01, …, 99 |
|
|
@@ -432,44 +433,9 @@ get_municipality(name_nepali="विराटनगर")
|
|
|
432
433
|
|
|
433
434
|
---
|
|
434
435
|
|
|
435
|
-
## For Django
|
|
436
|
+
## For Django
|
|
436
437
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
```python
|
|
440
|
-
INSTALLED_APPS = [
|
|
441
|
-
...
|
|
442
|
-
'nepali',
|
|
443
|
-
...
|
|
444
|
-
]
|
|
445
|
-
```
|
|
446
|
-
|
|
447
|
-
In your Template
|
|
448
|
-
|
|
449
|
-
```python
|
|
450
|
-
{% load nepalidatetime %}
|
|
451
|
-
```
|
|
452
|
-
|
|
453
|
-
```python
|
|
454
|
-
{% nepalinow %}
|
|
455
|
-
```
|
|
456
|
-
|
|
457
|
-
```python
|
|
458
|
-
{% nepalinow '%Y-%m-%d' %}
|
|
459
|
-
```
|
|
460
|
-
|
|
461
|
-
```python
|
|
462
|
-
{{ datetimeobj|nepalidate:"%Y-%m-%d" }}
|
|
463
|
-
{{ datetimeobj|nepalidate_en:"%Y-%m-%d" }}
|
|
464
|
-
```
|
|
465
|
-
|
|
466
|
-
```python
|
|
467
|
-
{{ datetimeobj|nepalihumanize }}
|
|
468
|
-
```
|
|
469
|
-
|
|
470
|
-
```python
|
|
471
|
-
{{ forloop.counter|nepalinumber }}
|
|
472
|
-
```
|
|
438
|
+
We have created a new Django package called [django-nepali](https://github.com/opensource-nepal/django-nepali) to support `nepali` package. For more information, please visit [django-nepali](https://github.com/opensource-nepal/django-nepali).
|
|
473
439
|
|
|
474
440
|
## Contribution
|
|
475
441
|
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
|
|
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 = (
|
|
2
10
|
"Baishakh",
|
|
3
11
|
"Jestha",
|
|
4
12
|
"Ashad",
|
|
@@ -13,7 +21,8 @@ MONTHS_EN = (
|
|
|
13
21
|
"Chaitra",
|
|
14
22
|
)
|
|
15
23
|
|
|
16
|
-
|
|
24
|
+
# Nepali months in Nepali (devanagari)
|
|
25
|
+
NEPALI_MONTHS_NE = (
|
|
17
26
|
"बैशाख",
|
|
18
27
|
"जेठ",
|
|
19
28
|
"असार",
|
|
@@ -28,6 +37,7 @@ MONTHS_NE = (
|
|
|
28
37
|
"चैत",
|
|
29
38
|
)
|
|
30
39
|
|
|
40
|
+
# Week names in english
|
|
31
41
|
WEEKS_EN = (
|
|
32
42
|
"Sunday",
|
|
33
43
|
"Monday",
|
|
@@ -38,8 +48,10 @@ WEEKS_EN = (
|
|
|
38
48
|
"Saturday",
|
|
39
49
|
)
|
|
40
50
|
|
|
51
|
+
# Week abbreviation name in english
|
|
41
52
|
WEEKS_ABBR_EN = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")
|
|
42
53
|
|
|
54
|
+
# Weeks names in Nepali (devanagari)
|
|
43
55
|
WEEKS_NE = (
|
|
44
56
|
"आइतबार",
|
|
45
57
|
"सोमबार",
|
|
@@ -50,4 +62,5 @@ WEEKS_NE = (
|
|
|
50
62
|
"शनिबार",
|
|
51
63
|
)
|
|
52
64
|
|
|
65
|
+
# Week abbreviation name in Nepali (devanagari)
|
|
53
66
|
WEEKS_ABBR_NE = ("आइत", "सोम", "मंगल", "बुध", "बिही", "शुक्र", "शनि")
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from ._datetime import nepalidate,
|
|
1
|
+
from ._datetime import nepalidate, nepalidatetime, nepalitime
|
|
2
2
|
from ._formatter import NepaliDateTimeFormatter
|
|
3
3
|
from ._humanize import HumanizeDateTime, nepalihumanize
|
|
4
4
|
from ._nepalimonth import nepalimonth
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import datetime as pythonDateTime
|
|
2
2
|
|
|
3
3
|
from nepali.date_converter import converter as nepali_date_converter
|
|
4
|
-
from nepali.timezone import NepaliTimeZone,
|
|
4
|
+
from nepali.timezone import NepaliTimeZone, to_nepali_timezone, utc_now
|
|
5
5
|
|
|
6
6
|
from ._nepalimonth import nepalimonth
|
|
7
7
|
|
|
@@ -17,31 +17,31 @@ class formatter_class_mixin:
|
|
|
17
17
|
|
|
18
18
|
@classmethod
|
|
19
19
|
def init_formatter_class(cls):
|
|
20
|
-
if not hasattr(cls, "
|
|
20
|
+
if not hasattr(cls, "_formatter_class_cache"):
|
|
21
21
|
from ._formatter import NepaliDateTimeFormatter
|
|
22
22
|
|
|
23
|
-
cls.
|
|
24
|
-
return cls.
|
|
23
|
+
cls._formatter_class_cache = NepaliDateTimeFormatter
|
|
24
|
+
return cls._formatter_class_cache
|
|
25
25
|
|
|
26
26
|
@classmethod
|
|
27
27
|
def get_strptime_method(cls):
|
|
28
|
-
if not hasattr(cls, "
|
|
28
|
+
if not hasattr(cls, "_strptime_method_cache"):
|
|
29
29
|
from .parser import strptime
|
|
30
30
|
|
|
31
|
-
cls.
|
|
32
|
-
return cls.
|
|
31
|
+
cls._strptime_method_cache = strptime
|
|
32
|
+
return cls._strptime_method_cache
|
|
33
33
|
|
|
34
34
|
def strftime(self, format: str) -> str:
|
|
35
35
|
return self.strftime_en(format)
|
|
36
36
|
|
|
37
37
|
def strftime_en(self, format: str) -> str:
|
|
38
|
-
|
|
39
|
-
formatter =
|
|
38
|
+
nepali_datetime_formatter = self.get_formatter_class()
|
|
39
|
+
formatter = nepali_datetime_formatter(self, devanagari=False)
|
|
40
40
|
return formatter.get_str(format)
|
|
41
41
|
|
|
42
42
|
def strftime_ne(self, format: str) -> str:
|
|
43
|
-
|
|
44
|
-
formatter =
|
|
43
|
+
nepali_datetime_formatter = self.get_formatter_class()
|
|
44
|
+
formatter = nepali_datetime_formatter(self, devanagari=True)
|
|
45
45
|
return formatter.get_str(format)
|
|
46
46
|
|
|
47
47
|
|
|
@@ -194,12 +194,11 @@ class nepalidate(formatter_class_mixin):
|
|
|
194
194
|
|
|
195
195
|
@staticmethod
|
|
196
196
|
def from_date(date_object):
|
|
197
|
-
|
|
197
|
+
return nepalidate(
|
|
198
198
|
*nepali_date_converter.english_to_nepali(
|
|
199
199
|
date_object.year, date_object.month, date_object.day
|
|
200
200
|
)
|
|
201
201
|
)
|
|
202
|
-
return npDate
|
|
203
202
|
|
|
204
203
|
@staticmethod
|
|
205
204
|
def from_nepalidatetime(datetime_object):
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import datetime as pythonDateTime
|
|
2
|
+
|
|
2
3
|
from nepali import number
|
|
3
4
|
from nepali.exceptions import (
|
|
4
5
|
InvalidDateFormatException,
|
|
@@ -40,7 +41,7 @@ class NepaliDateTimeFormatter:
|
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
def __init__(self, datetime_object, devanagari=False):
|
|
43
|
-
# TODO: Change variable npDateTime into
|
|
44
|
+
# TODO: Change variable npDateTime into snake case: `np_date_time`
|
|
44
45
|
if type(datetime_object) == nepalidatetime:
|
|
45
46
|
self.npDateTime = datetime_object
|
|
46
47
|
elif type(datetime_object) == nepalidate:
|
|
@@ -100,7 +101,7 @@ class NepaliDateTimeFormatter:
|
|
|
100
101
|
|
|
101
102
|
def get_format_map(self, ch: str) -> str:
|
|
102
103
|
if ch not in self.format_map:
|
|
103
|
-
raise InvalidDateFormatException("Invalid Date format %{}"
|
|
104
|
+
raise InvalidDateFormatException(f"Invalid Date format %{ch}")
|
|
104
105
|
return self.format_map[ch]
|
|
105
106
|
|
|
106
107
|
@property
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import datetime as pythonDateTime
|
|
2
|
-
|
|
3
1
|
from nepali import number
|
|
4
|
-
from nepali.timezone import now
|
|
5
|
-
from nepali.exceptions import InvalidNepaliDateTimeObjectException
|
|
2
|
+
from nepali.timezone import now
|
|
6
3
|
|
|
7
|
-
from .
|
|
4
|
+
from .utils import to_nepalidatetime
|
|
8
5
|
|
|
9
6
|
|
|
10
7
|
class HumanizeDateTime:
|
|
@@ -29,20 +26,7 @@ class HumanizeDateTime:
|
|
|
29
26
|
threshold (kwargs): threshold to be humanize
|
|
30
27
|
format (kwargs): format to display behind threshold
|
|
31
28
|
"""
|
|
32
|
-
|
|
33
|
-
self.datetime_obj = datetime_obj.to_datetime()
|
|
34
|
-
elif type(datetime_obj) == nepalidate:
|
|
35
|
-
self.datetime_obj = nepalidatetime.from_nepali_date(
|
|
36
|
-
datetime_obj
|
|
37
|
-
).to_datetime()
|
|
38
|
-
elif type(datetime_obj) == pythonDateTime.date:
|
|
39
|
-
self.datetime_obj = nepalidatetime.from_date(datetime_obj).to_datetime()
|
|
40
|
-
elif type(datetime_obj) == pythonDateTime.datetime:
|
|
41
|
-
self.datetime_obj = to_nepali_timezone(datetime_obj)
|
|
42
|
-
else:
|
|
43
|
-
raise InvalidNepaliDateTimeObjectException(
|
|
44
|
-
"Argument must be instance of NepaliDate or NepaliDateTime or datetime.datetime or datetime.date"
|
|
45
|
-
)
|
|
29
|
+
self.datetime_obj = to_nepalidatetime(datetime_obj)
|
|
46
30
|
|
|
47
31
|
self.threshold = kwargs.get("threshold")
|
|
48
32
|
self.format = kwargs.get("format")
|
|
@@ -53,8 +37,11 @@ class HumanizeDateTime:
|
|
|
53
37
|
def __calc_seconds(self):
|
|
54
38
|
"""calculates total seconds from now"""
|
|
55
39
|
current_date_time = now()
|
|
56
|
-
|
|
57
|
-
|
|
40
|
+
|
|
41
|
+
# TODO (@aj3sh): support datetime - nepalidatetime
|
|
42
|
+
self.seconds = int(
|
|
43
|
+
(current_date_time - self.datetime_obj.to_datetime()).total_seconds()
|
|
44
|
+
)
|
|
58
45
|
|
|
59
46
|
self.interval_tense = self.__past_text
|
|
60
47
|
if self.seconds < 0:
|
|
@@ -67,13 +54,12 @@ class HumanizeDateTime:
|
|
|
67
54
|
"""returns humanize string"""
|
|
68
55
|
seconds = self.__calc_seconds() # calculating seconds
|
|
69
56
|
|
|
70
|
-
if self.threshold is not None:
|
|
71
|
-
|
|
72
|
-
return self.get_datetime().strip()
|
|
57
|
+
if self.threshold is not None and seconds >= self.threshold:
|
|
58
|
+
return self._get_datetime_str().strip()
|
|
73
59
|
|
|
74
|
-
return self.
|
|
60
|
+
return self._get_humanize_str().strip()
|
|
75
61
|
|
|
76
|
-
def
|
|
62
|
+
def _get_humanize_str(self):
|
|
77
63
|
"""
|
|
78
64
|
returns humanize datetime
|
|
79
65
|
"""
|
|
@@ -118,14 +104,13 @@ class HumanizeDateTime:
|
|
|
118
104
|
str(interval_value) + " " + str(interval_text) + " " + self.interval_tense
|
|
119
105
|
)
|
|
120
106
|
|
|
121
|
-
def
|
|
107
|
+
def _get_datetime_str(self):
|
|
122
108
|
"""
|
|
123
109
|
returns date in nepali characters
|
|
124
110
|
"""
|
|
125
111
|
if not self.format:
|
|
126
112
|
self.format = "%B %d, %Y"
|
|
127
|
-
|
|
128
|
-
return ndt.strftime_ne(self.format)
|
|
113
|
+
return self.datetime_obj.strftime_ne(self.format)
|
|
129
114
|
|
|
130
115
|
def __str__(self):
|
|
131
116
|
return self.to_str()
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from functools import cached_property
|
|
2
2
|
from typing import Any, Dict, Optional, Union
|
|
3
3
|
|
|
4
|
-
from .constants import
|
|
4
|
+
from nepali.constants import NEPALI_MONTHS_EN, NEPALI_MONTHS_NE
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
class NepaliMonthMeta(type):
|
|
@@ -40,7 +40,8 @@ class NepaliMonthMeta(type):
|
|
|
40
40
|
|
|
41
41
|
return cls._cache[value]
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
@staticmethod
|
|
44
|
+
def _parse_str(month: str) -> int:
|
|
44
45
|
"""
|
|
45
46
|
Parses str value of the month and returns int.
|
|
46
47
|
|
|
@@ -54,7 +55,7 @@ class NepaliMonthMeta(type):
|
|
|
54
55
|
return int(month)
|
|
55
56
|
|
|
56
57
|
month = month.capitalize()
|
|
57
|
-
month_names =
|
|
58
|
+
month_names = NEPALI_MONTHS_EN + NEPALI_MONTHS_NE
|
|
58
59
|
try:
|
|
59
60
|
index = month_names.index(month)
|
|
60
61
|
except ValueError:
|
|
@@ -66,7 +67,7 @@ class NepaliMonthMeta(type):
|
|
|
66
67
|
class nepalimonth(metaclass=NepaliMonthMeta):
|
|
67
68
|
"""
|
|
68
69
|
Represents Nepali month: Baishakh, Jestha, ..., Chaitra.
|
|
69
|
-
|
|
70
|
+
Baishakh: 1,
|
|
70
71
|
Jestha: 2,
|
|
71
72
|
...
|
|
72
73
|
Chaitra: 12
|
|
@@ -107,9 +108,9 @@ class nepalimonth(metaclass=NepaliMonthMeta):
|
|
|
107
108
|
@cached_property
|
|
108
109
|
def name(self) -> str:
|
|
109
110
|
"""Month's english name"""
|
|
110
|
-
return
|
|
111
|
+
return NEPALI_MONTHS_EN[self.__value - 1]
|
|
111
112
|
|
|
112
113
|
@cached_property
|
|
113
114
|
def name_ne(self) -> str:
|
|
114
115
|
"""Month's nepali name"""
|
|
115
|
-
return
|
|
116
|
+
return NEPALI_MONTHS_NE[self.__value - 1]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from functools import cached_property
|
|
2
2
|
from typing import Any, Dict, Optional, Union
|
|
3
3
|
|
|
4
|
-
from .constants import
|
|
4
|
+
from nepali.constants import WEEKS_ABBR_EN, WEEKS_ABBR_NE, WEEKS_EN, WEEKS_NE
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
class NepaliWeekMeta(type):
|
|
@@ -28,7 +28,7 @@ class NepaliWeekMeta(type):
|
|
|
28
28
|
pass
|
|
29
29
|
|
|
30
30
|
# checking if week is valid
|
|
31
|
-
if value is None or not
|
|
31
|
+
if value is None or not 0 <= value <= 6:
|
|
32
32
|
raise ValueError(f"Invalid week: {week}")
|
|
33
33
|
|
|
34
34
|
# checking cache
|
|
@@ -37,7 +37,8 @@ class NepaliWeekMeta(type):
|
|
|
37
37
|
|
|
38
38
|
return cls._cache[value]
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
@staticmethod
|
|
41
|
+
def _parse_str(week: str) -> int:
|
|
41
42
|
"""
|
|
42
43
|
Parses str value of the week and returns int.
|
|
43
44
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from nepali.exceptions import
|
|
1
|
+
from nepali.exceptions import FormatNotMatchException, InvalidDateTimeFormatException
|
|
2
2
|
|
|
3
3
|
from .validators import validate
|
|
4
4
|
|
|
@@ -53,10 +53,8 @@ def _get_standard_formats():
|
|
|
53
53
|
for time_format in STANDARD_TIME_FORMAT:
|
|
54
54
|
for date_format in STANDARD_DATE_FORMAT:
|
|
55
55
|
_standard_datetime_format_CACHE += [
|
|
56
|
-
"{} {}"
|
|
57
|
-
|
|
58
|
-
_standard_datetime_format_CACHE += [
|
|
59
|
-
"{}, {}".format(date_format, time_format)
|
|
56
|
+
f"{date_format} {time_format}",
|
|
57
|
+
f"{date_format}, {time_format}",
|
|
60
58
|
]
|
|
61
59
|
return _standard_datetime_format_CACHE
|
|
62
60
|
|
|
@@ -67,10 +65,10 @@ def parse(datetime_str):
|
|
|
67
65
|
eg. parse('2078-10-12') => <NepaliDateTime: 2078-10-12>
|
|
68
66
|
"""
|
|
69
67
|
standard_formats = _get_standard_formats()
|
|
70
|
-
nepalidatetime_object = None
|
|
71
68
|
for format in standard_formats:
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
try:
|
|
70
|
+
return strptime(datetime_str, format=format)
|
|
71
|
+
except FormatNotMatchException:
|
|
72
|
+
pass
|
|
75
73
|
|
|
76
74
|
raise InvalidDateTimeFormatException("Invalid format to parse nepali datetime.")
|