Skip to main content

A Python package to convert dates between Gregorian and Ethiopian calendars.

Project description

markdown Copy

Ethiopian Date Converter

A Python package to convert dates between the Gregorian and Ethiopian calendars. It supports localization, formatting, and various utilities for working with Ethiopian dates.


Installation

You can install the package using pip install py-ethiopian-date-converter

Features

Date Conversion:

  • Convert Gregorian dates to Ethiopian dates.
  • Convert Ethiopian dates to Gregorian dates.

Formatting:

  • Format Ethiopian dates with month names and time.

Utilities:

  • Check if a year is a leap year in the Ethiopian calendar.
  • Get the number of days in a month.
  • Add days or years to an Ethiopian date.
  • Compare Ethiopian dates.
  • Calculate the difference in days between two dates.

Usage

Basic Conversion

from ethiopian_date_converter import to_ethiopian, to_gregorian, EthDate

# Convert Gregorian to Ethiopian
gregorian_date = "2023-10-05"
ethiopian_date = to_ethiopian(gregorian_date)
print("Ethiopian Date:", ethiopian_date)  # Output: EthDate(day=25, month=1, year=2016)

# Convert Ethiopian to Gregorian
ethiopian_date = EthDate(25, 1, 2016)
gregorian_date = to_gregorian(ethiopian_date)
print("Gregorian Date:", gregorian_date.strftime("%Y-%m-%d"))  # Output: 2023-10-06

# Localization
# Get month name in Amharic
month_name = get_et_month_name(1, locale="AMH")
print("Month Name:", month_name)  # Output: መስከረም

# Get month name in African Orthodox
month_name = get_et_month_name(1, locale="AO")
print("Month Name:", month_name)  # Output: Fulbaana

# Format Ethiopian date
ethiopian_date = EthDate(25, 1, 2016)
print("Formatted Date:", ethiopian_date.formatted)  # Output: መስከረም 25, 2016

# Check if a year is a leap year
print("Is 2015 a leap year?", EthDate(1, 1, 2015).is_leap_year)  # Output: True

# Add days to a date
new_date = EthDate(1, 1, 2016).add_days(30)
print("New Date:", new_date)  # Output: EthDate(day=1, month=2, year=2016)

# Compare dates
date1 = EthDate(1, 1, 2016)
date2 = EthDate(2, 1, 2016)
print("Is date1 earlier than date2?", date1 < date2)  # Output: True

# Format Ethiopian date
ethiopian_date = EthDate(25, 1, 2016)
print("Formatted Date:", ethiopian_date.formatted)  # Output: መስከረም 25, 2016

# Get the number of days in a month
days = ethiopian_month_length(1, 2016)
print("Days in January 2016:", days)  # Output: 30

# Get the day of the week
day_of_week = EthDate(1, 1, 2016).day_of_week
print("Day of the week:", day_of_week)  # Output: ሰኞ


# Check if a year is a leap year
print("Is 2015 a leap year?", EthDate(1, 1, 2015).is_leap_year)  # Output: True

# Add days to a date
new_date = EthDate(1, 1, 2016).add_days(30)
print("New Date:", new_date)  # Output: EthDate(day=1, month=2, year=2016)

# Compare dates
date1 = EthDate(1, 1, 2016)
date2 = EthDate(2, 1, 2016)
print("Is date1 earlier than date2?", date1 < date2)  # Output: True

# Ethiopian New Year (Meskerem 1)
ethiopian_new_year = to_ethiopian("2023-09-11")
print("Ethiopian New Year:", ethiopian_new_year)  # Output: EthDate(day=1, month=1, year=2016)

# Ethiopian Christmas (Tir 29)
ethiopian_christmas = to_ethiopian("2023-01-07")
print("Ethiopian Christmas:", ethiopian_christmas)  # Output: EthDate(day=28, month=4, year=2015)

# Calculate the difference between two dates
date1 = EthDate(1, 1, 2016)
date2 = EthDate(2, 1, 2016)
diff = date1 - date2
print("Difference:", diff)  # Output: DateDiff(days=1, months=0, years=0, total_days=1)

# get date from dmy format
date = EthDate.from_dmy_format('27/01/1989')
print("Date:", date)  # Output: EthDate(day=27, month=1, year=1989) 

API Reference

Functions

  • to_ethiopian(gregorian_date: str) -> EthDate: Convert a Gregorian date to an Ethiopian date.

  • to_gregorian(ethiopian_date: EthDate) -> datetime: Convert an Ethiopian date to a Gregorian date.

  • is_leap_year_et(year: int) -> bool: Check if a year is a leap year in the Ethiopian calendar.

  • ethiopian_month_length(month: int, year: int) -> int: Get the number of days in a month.

  • get_et_month_name(month: int, locale: str = "AMH") -> str: Get the name of an Ethiopian month.

Class

  • EthDate(day: int, month: int, year: int): Represents an Ethiopian date.

  • add_days(days: int) -> EthDate: Add days to the date.

  • add_years(years: int) -> EthDate: Add years to the date.

  • to_gregorian() -> datetime: Convert the date to a Gregorian date.

  • is_leap_year -> bool: Check if the year is a leap year.

  • month_length -> int: Get the number of days in the month.

  • day_of_week -> str: Get the day of the week in Amharic.

  • formatted -> str: Get the formatted date string.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

Future Features

  • integrate with django
  • add timedelta

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

py_ethiopian_date_converter-0.1.1.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

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

py_ethiopian_date_converter-0.1.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file py_ethiopian_date_converter-0.1.1.tar.gz.

File metadata

File hashes

Hashes for py_ethiopian_date_converter-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7fdb707dcb8494ee39d8440b2b63b458a1d10a8b7a9166eed20134c61291f025
MD5 895a4a3b6386fa8349e2ac6d38ff9ab2
BLAKE2b-256 3874808cdca09685b3f1e38d3f03394e192d2d3950380b412dd0dee4d460d564

See more details on using hashes here.

File details

Details for the file py_ethiopian_date_converter-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for py_ethiopian_date_converter-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ffd40ed11ac3878fdab9a8b375017407857178eabd5d60a401edc5e6dfa3eed3
MD5 0e9dae4bf9e988889baf58c5ea6cf174
BLAKE2b-256 c40e796bcd2a55fc25ffded2152c79d9245a9f7bc0ae800360ec1af337086426

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