SushilShrestha / pyBSDate

BS to AD and AD to BS date conversion utility
MIT License
14 stars 10 forks source link

ValueError: day is out of range for month #1

Closed ghost closed 4 years ago

ghost commented 8 years ago

    File "/home/ays/alms-env/alms/pyBSDate/BSDate.py", line 23, in convert_to_bs

        date_components = decompose_date(ad_date)

        year, month, day = date_components

        validate_date_ad(year, month, day)

        bs_year, bs_month, bs_day = _ad_to_bs(year, month, day)

        return datetime.date(bs_year, bs_month, bs_day)

    >>> bs_day
    31
    >>> bs_month
    4
    >>> bs_year
    2072
    >>> 

    ValueError: day is out of range for month

The error is in the last line when the datetime object is returned. The problem, afaik is that the BS month-days are incompatable with the AD month dates, i.e the no. of days per month in BS.

SushilShrestha commented 8 years ago

The problem is you can't use python's datetime module to create BS date.

return datetime.date(bs_year, bs_month, bs_day)

python datetime module is only for AD Dates. 2072-04-31 throws exception because April(4th month) always contains 30 days in AD date. Whereas 2072-04-31 is perfectly valid date for BS date.

ghost commented 8 years ago

ya thats why i asked if you know a solution to this? Is there any other datetime object i can use for localized date storage?

SushilShrestha commented 8 years ago

For localized date storage, you can just create your object or It may be a new feature here in this library. Can you specify what features do you want for the object?

ghost commented 8 years ago

I would like to store the nepali date in an abstract class which extends datetime.date Sort of like this,

class ndatetime(detetime.date):
    def __init__(self, *args, **kwargs):
        pass

something like that

SushilShrestha commented 4 years ago

The feature has been implemented on 81d8c42f2016efe5f2ef1a6d8708d069cc7b9fa6 and will be shipped on v0.3.0