diff --git a/bikram/bikram.py b/bikram/bikram.py index 295a838..0cfb252 100644 --- a/bikram/bikram.py +++ b/bikram/bikram.py @@ -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 @@ -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): @@ -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): diff --git a/bikram/constants.py b/bikram/constants.py index fcbfc6b..cb8215c 100644 --- a/bikram/constants.py +++ b/bikram/constants.py @@ -183,4 +183,4 @@ )) FIRST_AD_YEAR = next(iter(BS_YEAR_TO_MONTHS)) -LAST_AD_YEAR = next(reversed(BS_YEAR_TO_MONTHS)) \ No newline at end of file +LAST_AD_YEAR = next(reversed(BS_YEAR_TO_MONTHS)) diff --git a/tests/test_samwat.py b/tests/test_samwat.py index a2aa3a7..7ec15d0 100755 --- a/tests/test_samwat.py +++ b/tests/test_samwat.py @@ -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):