Skip to content

Commit

Permalink
dipee pull request confirmed
Browse files Browse the repository at this point in the history
  • Loading branch information
acpmasquerade committed Jun 17, 2024
1 parent 5e7be9e commit 5433e7f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
24 changes: 15 additions & 9 deletions bikram/bikram.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
_LAST_BS_DATE = {"year": LAST_AD_YEAR, "month": 12, "day": BS_YEAR_TO_MONTHS[LAST_AD_YEAR][-1]}


# @TODO: 0 is considered as TypeError ? , shouldn't it be a ValueError ??
def _check_int_value(value):
if isinstance(value, int) and value > 0:
return value
Expand All @@ -50,15 +51,20 @@ def _check_int_value(value):


def _get_max_days_in_month(year, month):
try:
days = BS_YEAR_TO_MONTHS[year][month]
if not days:
raise ValueError('Invalid month value')
return days
except KeyError:
if month < 1 or month > 12:
raise ValueError('Invalid month value, supported range is 1-12')
if year < FIRST_AD_YEAR or year > LAST_AD_YEAR:
raise ValueError(f'Invalid year, supported range is {FIRST_AD_YEAR}-{LAST_AD_YEAR}')
except IndexError:
raise ValueError('Invalid month value')
return BS_YEAR_TO_MONTHS[year][month]
# try:
# days = BS_YEAR_TO_MONTHS[year][month]
# if not days:
# raise ValueError('Invalid month value')
# return days
# except KeyError:
# raise ValueError(f'Invalid year, supported range is {FIRST_AD_YEAR}-{LAST_AD_YEAR}')
# except IndexError:
# raise ValueError('Invalid month value')


def _check_date_values(year, month, day):
Expand All @@ -69,7 +75,7 @@ def _check_date_values(year, month, day):
if year < FIRST_AD_YEAR or year > LAST_AD_YEAR:
raise ValueError(f'Invalid year, supported range is {FIRST_AD_YEAR}-{LAST_AD_YEAR}')

if month > 12:
if month < 1 or month > 12:
raise ValueError('Invalid month, supported range is 1-12')

if day > _get_max_days_in_month(year, month):
Expand Down
2 changes: 1 addition & 1 deletion bikram/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,4 @@
))

FIRST_AD_YEAR = next(iter(BS_YEAR_TO_MONTHS))
LAST_AD_YEAR = next(reversed(BS_YEAR_TO_MONTHS))
LAST_AD_YEAR = next(reversed(BS_YEAR_TO_MONTHS))
1 change: 1 addition & 0 deletions tests/test_samwat.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ def setUp(self):
{"year": 2000, "month": "three", "day": 20},
{"year": 2000, "month": 4, "day": 0},
{"year": 2000, "month": 0, "day": 13},
{"year": 2000, "month": 0, "day": 0},
]

def test_samwat_date(self):
Expand Down

0 comments on commit 5433e7f

Please sign in to comment.