nepali 1.0.1__tar.gz → 1.1.1__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.

Files changed (51) hide show
  1. {nepali-1.0.1 → nepali-1.1.1}/PKG-INFO +11 -85
  2. {nepali-1.0.1 → nepali-1.1.1}/README.md +7 -84
  3. {nepali-1.0.1/nepali/datetime → nepali-1.1.1/nepali}/constants.py +15 -2
  4. {nepali-1.0.1 → nepali-1.1.1}/nepali/date_converter.py +4 -4
  5. {nepali-1.0.1 → nepali-1.1.1}/nepali/datetime/__init__.py +1 -1
  6. {nepali-1.0.1 → nepali-1.1.1}/nepali/datetime/_datetime.py +12 -13
  7. {nepali-1.0.1 → nepali-1.1.1}/nepali/datetime/_formatter.py +3 -2
  8. {nepali-1.0.1 → nepali-1.1.1}/nepali/datetime/_humanize.py +14 -29
  9. {nepali-1.0.1 → nepali-1.1.1}/nepali/datetime/_nepalimonth.py +7 -6
  10. {nepali-1.0.1 → nepali-1.1.1}/nepali/datetime/_nepaliweek.py +4 -3
  11. {nepali-1.0.1 → nepali-1.1.1}/nepali/datetime/parser/__init__.py +1 -1
  12. {nepali-1.0.1 → nepali-1.1.1}/nepali/datetime/parser/_parser.py +7 -9
  13. {nepali-1.0.1 → nepali-1.1.1}/nepali/datetime/parser/validators.py +162 -78
  14. {nepali-1.0.1 → nepali-1.1.1}/nepali/datetime/utils.py +1 -0
  15. nepali-1.1.1/nepali/locations/__init__.py +3 -0
  16. {nepali-1.0.1 → nepali-1.1.1}/nepali/locations/_locations.py +1 -1
  17. {nepali-1.0.1 → nepali-1.1.1}/nepali/locations/utils.py +1 -2
  18. {nepali-1.0.1 → nepali-1.1.1}/nepali/number/_nepalinumber.py +26 -12
  19. {nepali-1.0.1 → nepali-1.1.1}/nepali/number/_number.py +1 -6
  20. {nepali-1.0.1 → nepali-1.1.1}/nepali/number/utils.py +1 -2
  21. {nepali-1.0.1 → nepali-1.1.1}/nepali/phone_number.py +2 -3
  22. {nepali-1.0.1 → nepali-1.1.1}/nepali/templatetags/nepalidatetime.py +37 -0
  23. {nepali-1.0.1 → nepali-1.1.1}/nepali/templatetags/nepalinumber.py +26 -0
  24. {nepali-1.0.1 → nepali-1.1.1}/nepali/tests/test_date_converter.py +17 -4
  25. {nepali-1.0.1 → nepali-1.1.1}/nepali/tests/test_datetime.py +3 -5
  26. {nepali-1.0.1 → nepali-1.1.1}/nepali/tests/test_humanize.py +1 -2
  27. {nepali-1.0.1 → nepali-1.1.1}/nepali/tests/test_number.py +35 -33
  28. {nepali-1.0.1 → nepali-1.1.1}/nepali/tests/test_timezone.py +6 -5
  29. {nepali-1.0.1 → nepali-1.1.1}/nepali/timezone.py +5 -3
  30. {nepali-1.0.1 → nepali-1.1.1}/nepali/utils.py +1 -1
  31. {nepali-1.0.1 → nepali-1.1.1}/nepali.egg-info/PKG-INFO +11 -85
  32. {nepali-1.0.1 → nepali-1.1.1}/nepali.egg-info/SOURCES.txt +1 -1
  33. {nepali-1.0.1 → nepali-1.1.1}/setup.py +12 -3
  34. nepali-1.0.1/nepali/locations/__init__.py +0 -3
  35. {nepali-1.0.1 → nepali-1.1.1}/LICENSE +0 -0
  36. {nepali-1.0.1 → nepali-1.1.1}/nepali/__init__.py +0 -0
  37. {nepali-1.0.1 → nepali-1.1.1}/nepali/char.py +0 -0
  38. {nepali-1.0.1 → nepali-1.1.1}/nepali/exceptions.py +0 -0
  39. {nepali-1.0.1 → nepali-1.1.1}/nepali/locations/_data.py +0 -0
  40. {nepali-1.0.1 → nepali-1.1.1}/nepali/locations/models.py +0 -0
  41. {nepali-1.0.1 → nepali-1.1.1}/nepali/number/__init__.py +1 -1
  42. {nepali-1.0.1 → nepali-1.1.1}/nepali/templatetags/__init__.py +0 -0
  43. {nepali-1.0.1 → nepali-1.1.1}/nepali/tests/__init__.py +0 -0
  44. {nepali-1.0.1 → nepali-1.1.1}/nepali/tests/test_locations.py +3 -3
  45. {nepali-1.0.1 → nepali-1.1.1}/nepali/tests/test_nepalimonth.py +0 -0
  46. {nepali-1.0.1 → nepali-1.1.1}/nepali/tests/test_nepaliweek.py +0 -0
  47. {nepali-1.0.1 → nepali-1.1.1}/nepali/tests/test_parser.py +0 -0
  48. {nepali-1.0.1 → nepali-1.1.1}/nepali/tests/test_phone_number.py +3 -3
  49. {nepali-1.0.1 → nepali-1.1.1}/nepali.egg-info/dependency_links.txt +0 -0
  50. {nepali-1.0.1 → nepali-1.1.1}/nepali.egg-info/top_level.txt +0 -0
  51. {nepali-1.0.1 → nepali-1.1.1}/setup.cfg +0 -0
@@ -1,10 +1,13 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nepali
3
- Version: 1.0.1
3
+ Version: 1.1.1
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
  [![PyPI version](https://badge.fury.io/py/nepali.svg)](https://badge.fury.io/py/nepali)
18
- [![CI status](https://github.com/opensource-nepal/py-nepali/actions/workflows/python-package.yml/badge.svg?branch=master)](https://github.com/opensource-nepal/py-nepali/actions)
21
+ [![CI status](https://github.com/opensource-nepal/py-nepali/actions/workflows/python-package.yml/badge.svg?branch=main)](https://github.com/opensource-nepal/py-nepali/actions)
19
22
  [![Downloads](https://img.shields.io/pypi/dm/nepali.svg?maxAge=180)](https://pypi.org/project/nepali/)
20
- [![codecov](https://codecov.io/gh/opensource-nepal/py-nepali/branch/master/graph/badge.svg?token=PTUHYWCJ4I)](https://codecov.io/gh/opensource-nepal/py-nepali)
23
+ [![codecov](https://codecov.io/gh/opensource-nepal/py-nepali/branch/main/graph/badge.svg?token=PTUHYWCJ4I)](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
 
@@ -307,11 +310,11 @@ np_datetime = parse("Jestha 15, 2079") # 2079-02-15 00:00:00
307
310
 
308
311
  | Directive | Meaning | Example |
309
312
  | --------- | --------------------------------------------------------- | ------------------------------ |
310
- | `%A` | Weekday as locale’s abbreviated name. | Sun, Mon, …, Sat (आइत, सोम, …) |
313
+ | `%a` | Weekday as locale’s abbreviated name. | Sun, Mon, …, Sat (आइत, सोम, …) |
311
314
  | `%A` | Weekday as locale’s full name. | Sunday, Monday, …, Saturday |
312
315
  | `%d` | Day of the month as a zero-padded decimal number. | 01, 02, …, 31 |
313
316
  | `%-d` | Day of the month as a decimal number. | 1, 2, …, 31 |
314
- | `%B` | Month as locale’s full name. | Baishak, Jestha, …, Chaitra |
317
+ | `%B` | Month as locale’s full name. | Baishakh, Jestha, …, Chaitra |
315
318
  | `%m` | Month as a zero-padded decimal number. | 01, 02, …, 12 |
316
319
  | `%-m` | Month as a decimal number. | 1, 2, …, 12 |
317
320
  | `%y` | Year without century as a zero-padded decimal number. | 00, 01, …, 99 |
@@ -447,87 +450,10 @@ get_municipality(name_nepali="विराटनगर")
447
450
 
448
451
  ---
449
452
 
450
- ## For Django Template
451
-
452
- Add `'nepali'` to your `INSTALLED_APPS` setting.
453
-
454
- ```python
455
- INSTALLED_APPS = [
456
- ...
457
- 'nepali',
458
- ...
459
- ]
460
- ```
461
-
462
- ### nepalidatetime
463
-
464
- In your Template
465
-
466
- ```python
467
- {% load nepalidatetime %}
468
- ```
469
-
470
- #### nepalinow
471
-
472
- `nepalinow` renders the current Nepali date and time in 'en-US' locale (English).
473
-
474
- ```python
475
- {% nepalinow %}
476
- ```
477
-
478
- ```python
479
- {% nepalinow '%Y-%m-%d' %}
480
- ```
481
-
482
- #### nepalinow_ne
483
-
484
- `nepalinow_ne` renders the current Nepali date and time in 'ne' locale (Nepali).
485
-
486
- ```python
487
- {% nepalinow_ne %}
488
- ```
489
-
490
- #### nepalidate
491
-
492
- `nepalidate` renders the datetime object into nepali datetime format in 'en-US' locale (English).
493
-
494
- ```python
495
- {{ datetime_obj|nepalidate:"%Y-%m-%d" }}
496
- ```
497
-
498
- #### nepalidate_ne
499
-
500
- `nepalidate_ne` renders the datetime object into nepali datetime format in 'ne' locale (Nepali).
501
-
502
- ```python
503
- {{ datetime_obj|nepalidate_ne:"%Y-%m-%d" }}
504
- ```
505
-
506
- #### nepalihumanize
507
-
508
- `nepalihumanize` renders the datetime object to a human readable form for 'ne' locale (Nepali)
509
-
510
- ```python
511
- {{ datetime_obj|nepalihumanize }}
512
- ```
513
-
514
- ### nepalinumber
515
-
516
- In your Template
517
-
518
- ```python
519
- {% load nepalinumber %}
520
- ```
521
-
522
- `nepalinumber` renders the english number into nepali format (devanagari)
523
-
524
- ```python
525
- {{ forloop.counter|nepalinumber }}
526
-
527
- {{ 150|nepalinumber }}
528
- ```
453
+ ## For Django
529
454
 
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).
530
456
 
531
457
  ## Contribution
532
458
 
533
- We appreciate feedback and contribution to this package. To get started please see our [contribution guide](CONTRIBUTION.md)
459
+ We appreciate feedback and contribution to this package. To get started please see our [contribution guide](./CONTRIBUTING.md)
@@ -1,9 +1,9 @@
1
1
  # nepali
2
2
 
3
3
  [![PyPI version](https://badge.fury.io/py/nepali.svg)](https://badge.fury.io/py/nepali)
4
- [![CI status](https://github.com/opensource-nepal/py-nepali/actions/workflows/python-package.yml/badge.svg?branch=master)](https://github.com/opensource-nepal/py-nepali/actions)
4
+ [![CI status](https://github.com/opensource-nepal/py-nepali/actions/workflows/python-package.yml/badge.svg?branch=main)](https://github.com/opensource-nepal/py-nepali/actions)
5
5
  [![Downloads](https://img.shields.io/pypi/dm/nepali.svg?maxAge=180)](https://pypi.org/project/nepali/)
6
- [![codecov](https://codecov.io/gh/opensource-nepal/py-nepali/branch/master/graph/badge.svg?token=PTUHYWCJ4I)](https://codecov.io/gh/opensource-nepal/py-nepali)
6
+ [![codecov](https://codecov.io/gh/opensource-nepal/py-nepali/branch/main/graph/badge.svg?token=PTUHYWCJ4I)](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
 
@@ -293,11 +293,11 @@ np_datetime = parse("Jestha 15, 2079") # 2079-02-15 00:00:00
293
293
 
294
294
  | Directive | Meaning | Example |
295
295
  | --------- | --------------------------------------------------------- | ------------------------------ |
296
- | `%A` | Weekday as locale’s abbreviated name. | Sun, Mon, …, Sat (आइत, सोम, …) |
296
+ | `%a` | Weekday as locale’s abbreviated name. | Sun, Mon, …, Sat (आइत, सोम, …) |
297
297
  | `%A` | Weekday as locale’s full name. | Sunday, Monday, …, Saturday |
298
298
  | `%d` | Day of the month as a zero-padded decimal number. | 01, 02, …, 31 |
299
299
  | `%-d` | Day of the month as a decimal number. | 1, 2, …, 31 |
300
- | `%B` | Month as locale’s full name. | Baishak, Jestha, …, Chaitra |
300
+ | `%B` | Month as locale’s full name. | Baishakh, Jestha, …, Chaitra |
301
301
  | `%m` | Month as a zero-padded decimal number. | 01, 02, …, 12 |
302
302
  | `%-m` | Month as a decimal number. | 1, 2, …, 12 |
303
303
  | `%y` | Year without century as a zero-padded decimal number. | 00, 01, …, 99 |
@@ -433,87 +433,10 @@ get_municipality(name_nepali="विराटनगर")
433
433
 
434
434
  ---
435
435
 
436
- ## For Django Template
437
-
438
- Add `'nepali'` to your `INSTALLED_APPS` setting.
439
-
440
- ```python
441
- INSTALLED_APPS = [
442
- ...
443
- 'nepali',
444
- ...
445
- ]
446
- ```
447
-
448
- ### nepalidatetime
449
-
450
- In your Template
451
-
452
- ```python
453
- {% load nepalidatetime %}
454
- ```
455
-
456
- #### nepalinow
457
-
458
- `nepalinow` renders the current Nepali date and time in 'en-US' locale (English).
459
-
460
- ```python
461
- {% nepalinow %}
462
- ```
463
-
464
- ```python
465
- {% nepalinow '%Y-%m-%d' %}
466
- ```
467
-
468
- #### nepalinow_ne
469
-
470
- `nepalinow_ne` renders the current Nepali date and time in 'ne' locale (Nepali).
471
-
472
- ```python
473
- {% nepalinow_ne %}
474
- ```
475
-
476
- #### nepalidate
477
-
478
- `nepalidate` renders the datetime object into nepali datetime format in 'en-US' locale (English).
479
-
480
- ```python
481
- {{ datetime_obj|nepalidate:"%Y-%m-%d" }}
482
- ```
483
-
484
- #### nepalidate_ne
485
-
486
- `nepalidate_ne` renders the datetime object into nepali datetime format in 'ne' locale (Nepali).
487
-
488
- ```python
489
- {{ datetime_obj|nepalidate_ne:"%Y-%m-%d" }}
490
- ```
491
-
492
- #### nepalihumanize
493
-
494
- `nepalihumanize` renders the datetime object to a human readable form for 'ne' locale (Nepali)
495
-
496
- ```python
497
- {{ datetime_obj|nepalihumanize }}
498
- ```
499
-
500
- ### nepalinumber
501
-
502
- In your Template
503
-
504
- ```python
505
- {% load nepalinumber %}
506
- ```
507
-
508
- `nepalinumber` renders the english number into nepali format (devanagari)
509
-
510
- ```python
511
- {{ forloop.counter|nepalinumber }}
512
-
513
- {{ 150|nepalinumber }}
514
- ```
436
+ ## For Django
515
437
 
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).
516
439
 
517
440
  ## Contribution
518
441
 
519
- We appreciate feedback and contribution to this package. To get started please see our [contribution guide](CONTRIBUTION.md)
442
+ We appreciate feedback and contribution to this package. To get started please see our [contribution guide](./CONTRIBUTING.md)
@@ -1,4 +1,12 @@
1
- MONTHS_EN = (
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
- MONTHS_NE = (
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 = ("आइत", "सोम", "मंगल", "बुध", "बिही", "शुक्र", "शनि")
@@ -78,7 +78,7 @@ class NepaliDateConverter:
78
78
  ((31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30), 365),
79
79
  ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
80
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),
81
+ ((31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31), 366), # 2050
82
82
  ((31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30), 365),
83
83
  ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
84
84
  ((31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30), 365),
@@ -98,7 +98,7 @@ class NepaliDateConverter:
98
98
  ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
99
99
  ((31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30), 365),
100
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),
101
+ ((31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30), 365), # 2070
102
102
  ((31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30), 365),
103
103
  ((31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30), 365),
104
104
  ((31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31), 366),
@@ -108,8 +108,8 @@ class NepaliDateConverter:
108
108
  ((31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31), 366),
109
109
  ((31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30), 365),
110
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),
112
- ((31, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30), 366),
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),
113
113
  ((30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30), 365),
114
114
  ((31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30), 365),
115
115
  ((31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30), 365),
@@ -1,4 +1,4 @@
1
- from ._datetime import nepalidate, nepalitime, nepalidatetime
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, utc_now, to_nepali_timezone
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, "__formatter_class__Cache"):
20
+ if not hasattr(cls, "_formatter_class_cache"):
21
21
  from ._formatter import NepaliDateTimeFormatter
22
22
 
23
- cls.__formatter_class__Cache = NepaliDateTimeFormatter
24
- return cls.__formatter_class__Cache
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, "_strptime_method_CACHE"):
28
+ if not hasattr(cls, "_strptime_method_cache"):
29
29
  from .parser import strptime
30
30
 
31
- cls._strptime_method_CACHE = strptime
32
- return cls._strptime_method_CACHE
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
- NepaliDateTimeFormatter = self.get_formatter_class()
39
- formatter = NepaliDateTimeFormatter(self, devanagari=False)
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
- NepaliDateTimeFormatter = self.get_formatter_class()
44
- formatter = NepaliDateTimeFormatter(self, devanagari=True)
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
- npDate = nepalidate(
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 snakecase: `np_date_time`
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 %{}".format(ch))
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, to_nepali_timezone
5
- from nepali.exceptions import InvalidNepaliDateTimeObjectException
2
+ from nepali.timezone import now
6
3
 
7
- from ._datetime import nepalidate, nepalidatetime
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
- if type(datetime_obj) == nepalidatetime:
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
- date = self.datetime_obj
57
- self.seconds = int((current_date_time - date).total_seconds())
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
- if seconds >= self.threshold:
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.get_humanize().strip()
60
+ return self._get_humanize_str().strip()
75
61
 
76
- def get_humanize(self):
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 get_datetime(self):
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
- ndt = nepalidatetime.from_datetime(self.datetime_obj)
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 MONTHS_EN, MONTHS_NE
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
- def _parse_str(cls, month: str) -> int:
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 = MONTHS_EN + MONTHS_NE
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
- Baishak: 1,
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 MONTHS_EN[self.__value - 1]
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 MONTHS_NE[self.__value - 1]
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 WEEKS_EN, WEEKS_NE, WEEKS_ABBR_EN, WEEKS_ABBR_NE
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 (0 <= value <= 6):
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
- def _parse_str(cls, week: str) -> int:
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 ._parser import strptime, parse
1
+ from ._parser import parse, strptime
2
2
 
3
3
  __all__ = [
4
4
  "strptime",
@@ -1,4 +1,4 @@
1
- from nepali.exceptions import InvalidDateTimeFormatException, FormatNotMatchException
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
- "{} {}".format(date_format, time_format)
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
- nepalidatetime_object = validate(datetime_str, format=format)
73
- if nepalidatetime_object is not None:
74
- return nepalidatetime_object
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.")