Library to convert BS date to AD date.
Python implementation of Date conversion From Bikram Sambat(BS) to English Date(AD) and viceversa. Conversion is done with the help of date mappings. So, conversion limited to 1971-2100 BS.
If you have pip installed, simply
pip install pyBSDate
OR from source:
git clone https://github.com/SushilShrestha/pyBSDate
python setup.py install
# Convert BS Date to AD Date
from pyBSDate import convert_BS_to_AD
ad_date = convert_BS_to_AD(2072, 1, 10)
print(ad_date)
# Convert AD Date to BS
from pyBSDate import convert_AD_to_BS
bs_date = convert_AD_to_BS(2015, 4, 23)
print(bs_date)
bsdate
and addate
classes are available for the date conversion. They inherit from the parent datetime.date
class and all the functions are similar to datetime.date
class.
Following code is the example of using the class based date.
from pyBSDate import bsdate
ne_date = bsdate(2077, 2, 32)
print(ne_date.strftime("%B %d %Y, %A", lang='ne')) # जेष्ठ ३२ २०७७, आइतबार
en_date = ne_date.addate
print (en_date.strftime("%B %d %Y, %A")) # June 14 2020, Sunday
Two date objects can also be compared
import datetime
from pyBSDate import bsdate, addate
ne_date = bsdate(2077, 2, 32)
en_date = addate(2010, 1, 12)
if ne_date > en_date:
print(ne_date.isoformat(lang='ne'))
Addition or substraction of timedelta
is also supported
ne_date = ne_date + datetime.timedelta(days=2)
For detailed information, refer to docs.
python -m unittest discover
Distributed under the MIT license. See LICENSE
for more information.
Date mapping data taken from https://github.com/bahadurbaniya/Date-Converter-Bikram-Sambat-to-English-Date
git checkout -b feature/fooBar
)git commit -am 'Add some fooBar'
)git push origin feature/fooBar
)The software might include bugs, if you find one help us improve the software by reporting it as an issue (https://github.com/SushilShrestha/pyBSDate/issues) or send us a pull request with the solution.
Peace ✌