Ethiopian calendar date conversion for Python
Project description
Ethiopian Date Converter for Python
High-performance Ethiopian calendar date conversion for Python applications with native C implementation.
Installation
# pip
pip install ethiopian-date-converter
# conda (if available)
conda install ethiopian-date-converter
Quick Start
from ethiopian_date_converter import (
EthiopicDate,
GregorianDate,
ethiopic_to_gregorian,
gregorian_to_ethiopic
)
# Using conversion functions
gregorian = ethiopic_to_gregorian(2017, 1, 1)
print(gregorian) # {'year': 2024, 'month': 9, 'day': 11}
ethiopic = gregorian_to_ethiopic(2024, 9, 11)
print(ethiopic) # {'year': 2017, 'month': 1, 'day': 1}
# Using date classes
ethiopic_date = EthiopicDate(2017, 1, 1)
gregorian_date = ethiopic_date.to_gregorian()
print(gregorian_date) # 2024-09-11
# Date arithmetic and formatting
new_year = EthiopicDate(2017, 1, 1)
print(new_year.get_month_name()) # "Meskerem"
print(new_year.get_day_of_week()) # "Wednesday"
print(new_year.format("DD MMMM YYYY")) # "01 Meskerem 2017"
next_month = new_year.add_months(1)
print(next_month) # 2017-02-01
Main Functionalities
Date Conversion
Convert dates between Ethiopian and Gregorian calendars with high accuracy:
# Ethiopian New Year 2017 to Gregorian
result = ethiopic_to_gregorian(2017, 1, 1)
print(result) # {'year': 2024, 'month': 9, 'day': 11}
# Ethiopian Christmas 2017 to Gregorian
result = ethiopic_to_gregorian(2017, 4, 29)
print(result) # {'year': 2025, 'month': 1, 'day': 7}
# Reverse conversions
result = gregorian_to_ethiopic(2025, 1, 7)
print(result) # {'year': 2017, 'month': 4, 'day': 29}
Date Classes with Rich Functionality
Work with powerful date objects that support arithmetic and formatting:
# Create Ethiopian date
date = EthiopicDate(2017, 1, 1)
# Date arithmetic
tomorrow = date.add_days(1)
next_month = date.add_months(1)
next_year = date.add_years(1)
# Calculate differences
christmas = EthiopicDate(2017, 4, 29)
days_until = christmas.diff_days(date)
print(f"Days until Christmas: {days_until}")
# Cross-calendar operations
gregorian_equivalent = date.to_gregorian()
print(f"Gregorian date: {gregorian_equivalent}")
Holiday Detection and Calendar Information
Automatically detect Ethiopian holidays and get calendar metadata:
new_year = EthiopicDate(2017, 1, 1)
print(new_year.is_holiday()) # True
print(new_year.get_holiday_name()) # "Ethiopian New Year"
christmas = EthiopicDate(2017, 4, 29)
print(christmas.is_holiday()) # True
print(christmas.get_holiday_name()) # "Ethiopian Christmas"
# Get calendar information
print(date.get_days_in_month()) # 30
print(date.is_leap_year()) # False (2017 % 4 != 3)
Formatting and Localization
Format dates with support for multiple languages:
date = EthiopicDate(2017, 1, 1)
# English formatting
print(date.format("YYYY-MM-DD")) # "2017-01-01"
print(date.format("DD MMMM YYYY")) # "01 Meskerem 2017"
print(date.format("DDDD, DD MMMM YYYY")) # "Wednesday, 01 Meskerem 2017"
# Amharic formatting
print(date.get_month_name("am")) # "መስከረም"
print(date.get_day_of_week("am")) # "ረቡዕ"
All Available Functions
Core Conversion Functions
ethiopic_to_gregorian(year, month, day, era=None)- Convert Ethiopian to Gregoriangregorian_to_ethiopic(year, month, day)- Convert Gregorian to Ethiopian
Validation Functions
is_valid_ethiopic_date(year, month, day)- Validate Ethiopian dateis_valid_gregorian_date(year, month, day)- Validate Gregorian dateis_gregorian_leap(year)- Check if Gregorian year is leap year
Date Classes
EthiopicDate(year, month, day)- Ethiopian calendar date with full functionalityGregorianDate(year, month, day)- Gregorian calendar date with conversion
Date Arithmetic Methods
add_days(days)- Add/subtract daysadd_months(months)- Add/subtract monthsadd_years(years)- Add/subtract yearsdiff_days(other_date)- Calculate difference in days
Formatting and Display
format(pattern, locale="en")- Format date with custom patternget_month_name(locale="en")- Get month name in specified languageget_day_of_week(locale="en")- Get weekday name in specified language
Calendar Information
get_days_in_month()- Get number of days in current monthis_leap_year()- Check if current year is leap yearis_holiday()- Check if date is a holidayget_holiday_name()- Get holiday name if applicable
Julian Day Number Functions
ethiopic_to_jdn(year, month, day, era=None)- Convert Ethiopian to JDNgregorian_to_jdn(year, month, day)- Convert Gregorian to JDNjdn_to_ethiopic(jdn, era=None)- Convert JDN to Ethiopianjdn_to_gregorian(jdn)- Convert JDN to Gregorianget_day_of_week(jdn)- Get weekday from JDN
Utility Functions
get_current_ethiopic_date()- Get current Ethiopian dateget_current_gregorian_date()- Get current Gregorian dategenerate_calendar(year, month, calendar_type)- Generate calendar gridget_business_days(start, end, exclude_holidays=True)- Calculate business daysget_holidays(year, calendar_type="ethiopic")- Get all holidays for yearcalculate_age(birth_date, reference_date=None)- Calculate agefind_next_holiday(start_date, max_days=365)- Find next holiday
Class Methods
EthiopicDate.from_gregorian(gregorian_date)- Create from GregorianEthiopicDate.from_jdn(jdn, era=None)- Create from JDNEthiopicDate.today()- Get current Ethiopian dateGregorianDate.from_ethiopic(ethiopic_date)- Create from EthiopianGregorianDate.today()- Get current Gregorian date
Constants
ETHIOPIC_MONTHS- Month names in English and AmharicGREGORIAN_MONTHS- Gregorian month namesWEEKDAYS- Weekday names in multiple languagesETHIOPIAN_HOLIDAYS- Built-in holiday definitionsJD_EPOCH_OFFSET_*- Julian Day epoch constants
Date Object Properties
All date objects have these properties:
date = EthiopicDate(2017, 1, 1)
print(date.year) # 2017
print(date.month) # 1
print(date.day) # 1
Calendar Systems
Ethiopian Calendar
- 13 months (12 months of 30 days + Pagume)
- Pagume: 5 days (normal year), 6 days (leap year)
- Leap year:
year % 4 == 3 - Supported range: 1000-3000 EC (recommended)
Gregorian Calendar
- Standard Gregorian calendar rules
- Full leap year support including century exceptions
- Compatible with Python's datetime module
Error Handling
The package provides clear error messages for invalid operations:
from ethiopian_date_converter.date_classes import InvalidDateError
try:
invalid_date = EthiopicDate(2017, 13, 7) # Invalid Pagume day
except InvalidDateError as e:
print(f"Error: {e}") # Error: Invalid Ethiopian date: 2017-13-7
try:
result = ethiopic_to_gregorian(2017, 0, 1) # Invalid month
except ValueError as e:
print(f"Error: {e}") # Error: Invalid Ethiopian date: 2017-0-1
Performance
- Native C implementation for core calculations
- Optimized for high-frequency conversions
- Zero external dependencies beyond Python standard library
- Thread-safe operations
- Memory efficient date objects
Supported Date Ranges
- Ethiopian Years: 1000 - 3000 EC (optimal range)
- Gregorian Years: 1007 - 4007 AD
- Modern Era: 1900 - 2100 AD (recommended for applications)
Examples
Age Calculation
from ethiopian_date_converter.utils import calculate_age
birth_date = EthiopicDate(2000, 1, 1)
age = calculate_age(birth_date)
print(f"Age: {age['years']} years, {age['months']} months, {age['days']} days")
Calendar Generation
from ethiopian_date_converter.utils import generate_calendar
# Generate Ethiopian calendar for Meskerem 2017
calendar = generate_calendar(2017, 1, "ethiopic")
print(f"Month: {calendar['month_name']}")
print(f"Days in month: {calendar['days_in_month']}")
for week in calendar['calendar_grid']:
print(week)
Business Days Calculation
from ethiopian_date_converter.utils import get_business_days
start = EthiopicDate(2017, 1, 1)
end = EthiopicDate(2017, 1, 30)
business_days = get_business_days(start, end, exclude_holidays=True)
print(f"Business days: {business_days}")
Documentation
For comprehensive documentation, advanced usage examples, and API reference, visit: https://github.com/abiywondimu5758/ethiopian-date-converter/tree/main/docs/python
Requirements
- Python 3.7 or higher
- C compiler (for building the native extension)
- Windows: Visual Studio Build Tools or MinGW
- macOS: Xcode Command Line Tools
- Linux: GCC
License
MIT License - see LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ethiopian_date_converter_py-1.0.0.tar.gz.
File metadata
- Download URL: ethiopian_date_converter_py-1.0.0.tar.gz
- Upload date:
- Size: 21.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df135c99da3877300117d2e75cad6ff1055d4dd517e7a2b9c5ce8936d58a9879
|
|
| MD5 |
04bf97a0577ec085bd8e7fd0b6bb8e66
|
|
| BLAKE2b-256 |
10b25f89a35ed31698cb43f80758662da800731367ff37aaf7794b9bdb89e403
|
File details
Details for the file ethiopian_date_converter_py-1.0.0-py3-none-any.whl.
File metadata
- Download URL: ethiopian_date_converter_py-1.0.0-py3-none-any.whl
- Upload date:
- Size: 19.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0709e6fb5666986f7e36de3033650dda90d0e4c5566da3fb204c24a8b058e935
|
|
| MD5 |
7b733f53c43e1d1fd6607b7fb76d4a3d
|
|
| BLAKE2b-256 |
4363a9cce384020c720b3653714998ddad7d19c56b4ec6f7e5ad56126b16dfef
|