diff --git a/.gitignore b/.gitignore index 8165ce7a..78e22076 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ build dist *.egg-info **/.vscode +**/*.mo locale/__init__.py \ No newline at end of file diff --git a/core/datetimes/ne_datetime.py b/core/datetimes/ne_datetime.py index ebfa49e0..2704e3c6 100644 --- a/core/datetimes/ne_datetime.py +++ b/core/datetimes/ne_datetime.py @@ -2,6 +2,7 @@ from nepalicalendar import NepDate from nepalicalendar import values import datetime as py_datetime + from .shared import datetimedelta """ diff --git a/core/datetimes/shared.py b/core/datetimes/shared.py index 790d8e77..a3282aa2 100644 --- a/core/datetimes/shared.py +++ b/core/datetimes/shared.py @@ -79,14 +79,11 @@ def from_timedelta(cls, td): return datetimedelta(years=0, months=0, days=td.days, seconds=td.seconds, microseconds=td.microseconds) def _add_years(self, dt): - from core import calendar - for i in range(abs(self._years)): - for j in range(calendar.yearmonthscount(dt.year)): - if self._years > 0: - dt = _add_month(dt) - else: - dt = _sub_month(dt) - return dt + while True: # there are many '29/02' in nepali calendar + try: + return dt.replace(year=dt.year + self._years) + except ValueError: + return (dt - datetimedelta(days=1)) + self def _add_months(self, dt): for i in range(abs(self._months)): diff --git a/core/datetimes/test_ad_datetime.py b/core/datetimes/test_ad_datetime.py index e4daeb60..47eb48c6 100644 --- a/core/datetimes/test_ad_datetime.py +++ b/core/datetimes/test_ad_datetime.py @@ -78,6 +78,12 @@ def test_add_sub_years(self): (dt - datetimedelta(years=-2))) self.assertEquals(core.datetime.date(2018, 10, 22), (dt - datetimedelta(years=2))) + dt = core.datetime.date(2020, 10, 29) + self.assertEquals(core.datetime.date(2021, 10, 29), + (dt + datetimedelta(years=1))) + dt = core.datetime.date(2024, 2, 29) + self.assertEquals(core.datetime.date(2023, 2, 28), + (dt + datetimedelta(years=1))) def test_add_sub_months(self): dt = core.datetime.date(2020, 10, 22) diff --git a/core/gql_queries.py b/core/gql_queries.py index 0d165810..9a33196b 100644 --- a/core/gql_queries.py +++ b/core/gql_queries.py @@ -9,6 +9,7 @@ class Meta: model = Officer interfaces = (graphene.relay.Node,) filter_fields = { + "id": ["exact"], "uuid": ["exact"], "code": ["exact", "icontains"], "last_name": ["exact", "icontains"],