Skip to main content

Convert Python datetime objects to Persian (Jalali) calendar dates.

Project description

Persian DateTime Converter

Persian DateTime Converter is a Python library that allows you to convert Python datetime objects to Persian (Jalali) calendar dates without relying on any external libraries. This is particularly useful for developers who need to work with Persian dates in Python applications.

Table of Contents

Installation

To install the package, you can use pip, the Python package installer. Run the following command in your terminal:

pip install persian_datetime_converter

This will download and install the persian_datetime_converter package from PyPI.

Usage

After installing the package, you can start using it to convert Gregorian (Python datetime) dates to Persian (Jalali) dates.

Basic Example

from persian_datetime_converter.converter import PersianDateConverter
import datetime

# Example datetime: 13th September 2024
dt = datetime.datetime(2024, 9, 13)

# Convert to Persian date
persian_date = PersianDateConverter.convert(dt)

print(f"Gregorian: {dt.year}-{dt.month}-{dt.day} -> Persian: {persian_date[0]}-{persian_date[1]}-{persian_date[2]}")
# Output: Gregorian: 2024-9-13 -> Persian: 1403-6-23

Additional Examples

Converting the Start of the Persian Year

dt = datetime.datetime(2023, 3, 21)  # 21st March 2023 (Start of Persian year 1402)
persian_date = PersianDateConverter.convert(dt)
print(persian_date)  # Output: (1402, 1, 1)

Converting the End of the Persian Year

dt = datetime.datetime(2022, 3, 20)  # 20th March 2022 (End of Persian year 1400)
persian_date = PersianDateConverter.convert(dt)
print(persian_date)  # Output: (1400, 12, 29)

Checking Leap Years

from persian_datetime_converter.converter import PersianDateConverter

print(PersianDateConverter.is_leap_gregorian(2024))  # Output: True
print(PersianDateConverter.is_leap_gregorian(2023))  # Output: False

API Reference

PersianDateConverter.convert(datetime_obj)

  • Description: Converts a Python datetime object to a Persian date.
  • Parameters:
    • datetime_obj (datetime): The Python datetime object to convert.
  • Returns: A tuple containing the Persian year, month, and day.

PersianDateConverter.is_leap_gregorian(year)

  • Description: Determines if a given Gregorian year is a leap year.
  • Parameters:
    • year (int): The Gregorian year to check.
  • Returns: True if the year is a leap year, False otherwise.

Contributing

Contributions are welcome! If you find a bug or have a feature request, please open an issue on the GitHub repository.

To contribute:

  1. Fork the repository.
  2. Create a new branch: git checkout -b feature/your-feature.
  3. Commit your changes: git commit -am 'Add a new feature'.
  4. Push to the branch: git push origin feature/your-feature.
  5. Submit a pull request.

Running Tests

To run tests, use the following command:

python -m unittest discover tests

Make sure all tests pass before submitting a pull request.

License

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

Contact

If you have any questions or need further information, feel free to contact me:

You can also open an issue on the GitHub repository for any inquiries or issues.


Thank you for using Persian DateTime Converter! Your contributions and feedback are always appreciated. e https://github.com/bahmany/persian_datetime_converter with your actual GitHub repository URL to make the README complete.

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

persian_datetime_converter-0.1.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file persian_datetime_converter-0.1.0.tar.gz.

File metadata

File hashes

Hashes for persian_datetime_converter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 81e0d19df767fa10ad1afe2c368fb672d2d527f3d1a63db149f4acc4f7d12dde
MD5 d191042745081c57384e8385b1e4d8cb
BLAKE2b-256 2f1b737e7e9cd60356f5b097999fc506fc4e57e66ab86da673b7f6269f3068dd

See more details on using hashes here.

File details

Details for the file persian_datetime_converter-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for persian_datetime_converter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 600919003ee3a14ecf82fe2cdd51b3b46fb943cd3c62fa0ae304ea60add3cc35
MD5 9ecfc2a663ca6eea18d8230e3a8f50fa
BLAKE2b-256 4e76a5496cd2133eb5e8923b6dc53f50827bf56b414cd6eb16ab7a126aa1da30

See more details on using hashes here.

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