Skip to main content

Python BS date conversion utility

Project description

pyBSDate

Library to convert BS date to AD date.

PyPI PyPI - Python Version PyPI - Downloads GitHub license

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.

Installation

If you have pip installed, simply

pip install pyBSDate

OR from source:

  1. Get a copy of the project. Download zip of the project or clone this repo:
git clone https://github.com/SushilShrestha/pyBSDate
  1. Open your terminal, navigate to the project folder and type
python setup.py install

Usage

Using functions

# 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)

Class based wrappers

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.

Development setup

Running test

python -m unittest discover

Release History

  • 0.3.0
    • add class based wrapper for date conversion
    • update documentations
  • 0.2.*
    • function based date conversion

Meta

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

Contributing

Creating a pull request

  1. Fork it (https://github.com/SushilShrestha/pyBSDate/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

Submit a Bug Report

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 ✌

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyBSDate-0.3.1.tar.gz (9.2 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page