Skip to main content

A Python package to convert AD dates to BS dates.

Project description

AD-BS Converter

A Python library for converting Gregorian calendar (AD) dates to Bikram Sambat (BS) dates used in Nepal.

Overview

This library provides functionality to convert dates from the Gregorian calendar (AD) to the Bikram Sambat (BS) calendar system, which is the official calendar of Nepal. The implementation uses a pre-defined lookup table for Nepali calendar data from 1970 BS (1913 AD) to 2082 BS (2026 AD) for accurate conversions.

Features

  • Convert AD dates to BS dates
  • Get formatted BS date in YYYY-MM-DD format
  • Get Nepali month names
  • Built-in validation for date ranges
  • LRU caching for improved performance

Installation

pip install ad_bs_converter

Usage

Basic Conversion

from datetime import date
from ad_bs_converter import ADToBSConverter

# Create a converter with an AD date
ad_date = date(2023, 5, 15)
converter = ADToBSConverter(ad_date)

# Get the BS date
bs_date = converter.get_bs_date()
print(bs_date)  # Output: 2080-2-1

# Get formatted date
formatted_date = converter.get_formatted()
print(formatted_date)  # Output: 2080-2-1

# Get Nepali month name
month_name = converter.get_month_name()
print(month_name)  # Output: Jestha

Cache Management

The library uses LRU caching to improve performance for repeated conversions.

# Configure cache size when creating a converter
converter = ADToBSConverter(date(2023, 5, 15), cache_size=256)

# Get cache information
cache_info = ADToBSConverter.get_cache_info()
print(cache_info)

# Clear the cache if needed
ADToBSConverter.clear_cache()

Error Handling

The library provides specific error handling for date range validation:

from datetime import date
from ad_bs_converter import ADToBSConverter
from ad_bs_converter.exceptions import ADDateOutOfBoundsError

try:
    # Try with a date outside the supported range
    converter = ADToBSConverter(date(1900, 1, 1))
except ADDateOutOfBoundsError as e:
    print(f"Error: {e}")

Supported Date Range

The converter supports AD dates from approximately 1913 to 2026, corresponding to BS dates from 1970 to 2082.

Documentation

For more detailed documentation including:

  • API reference
  • Implementation details
  • Calendar data sources

Please refer to the github link Aayush Dip Giri.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

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

ad_bs_converter-1.2.1.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ad_bs_converter-1.2.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file ad_bs_converter-1.2.1.tar.gz.

File metadata

  • Download URL: ad_bs_converter-1.2.1.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for ad_bs_converter-1.2.1.tar.gz
Algorithm Hash digest
SHA256 a5f60f45ef6dc54d6809cc03ec843d19f1278d247ff5f6792ca40c8b554baa29
MD5 c94cf2ba74095aea771c5d25336ed363
BLAKE2b-256 d7d46a208e2aa5d45830e5b15350b223a6228bb4f9ce14af201de03d1c2b4669

See more details on using hashes here.

File details

Details for the file ad_bs_converter-1.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ad_bs_converter-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c09a3247ca553934490a425a66c60cb45bb331d9d2dcc15628c490b3b77793f8
MD5 9612c225bf2a2cf6f9a5d6f735909b52
BLAKE2b-256 496efa120b0e851cff8d5a530e96fae68910029fba665c4909f0f8c4b67923d9

See more details on using hashes here.

Supported by

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