Skip to main content

A production-ready Python library for Ethiopian calendar and time conversions.

Project description

ethiotime

A production-ready, pure-Python library for Ethiopian calendar and time conversions. Designed for accuracy, reliability, and ease of use in any Python project (including FastAPI).

Features

  • Robust Calendar Conversion: Bi-directional conversion between Ethiopian (Amete Mihret) and Gregorian calendars.
  • Leap Year Support: Handles the Ethiopian 4-year cycle, including the 6-day Pagume month.
  • Ethiopian Time Conversion: Converts standard 24-hour time to the 12-hour Ethiopian system (where the day starts at 6 AM).
  • Production-Grade Validation: Strict type checking and value range validation for all inputs.
  • Zero Dependencies: Pure Python implementation with no external requirements.

Installation

From PyPI

pip install ethiotime

Local Development

To use the library locally or contribute to it:

git clone https://github.com/bikilaketema/ethiotime.git
cd ethiotime
pip install -e .

Usage

Calendar Conversion

from datetime import date
from ethiotime import CalendarService

# Ethiopian to Gregorian
# Example: Meskerem 1, 2017 EC
g_date = CalendarService.ec_to_gc(2017, 1, 1)
print(g_date)  # 2024-09-11

# Gregorian to Ethiopian
# Supports datetime.date objects or ISO strings (YYYY-MM-DD)
e_date_1 = CalendarService.gc_to_ec(date(2024, 9, 11))
e_date_2 = CalendarService.gc_to_ec("2024-09-11")

print(e_date_1)  # (2017, 1, 1)
print(e_date_2)  # (2017, 1, 1)

Time Conversion

from ethiotime import TimeService

# Standard Hour (0-23) to Ethiopian Hour (1-12)
# 6 AM (06:00) standard time is 12:00 in Ethiopia
eth_hour = TimeService.standard_to_ethiopian(6)
print(eth_hour)  # 12

# Ethiopian Hour (1-12) to Standard 12-hour clock
# 12:00 Ethiopian is 6:00 standard
std_hour = TimeService.ethiopian_to_standard(12)
print(std_hour)  # 6

Validation & Edge Cases

The library strictly validates all inputs:

  • Month must be 1-13.
  • Pagume (Month 13) is validated as 5 days for regular years and 6 days for leap years.
  • Standard hours must be 0-23.
  • Ethiopian hours must be 1-12.
  • All inputs must be integers; otherwise, a ValueError is raised.

Testing

To run the exhaustive test suite:

python3 -m unittest discover ethiotime/tests

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

ethiotime-1.0.2.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

ethiotime-1.0.2-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file ethiotime-1.0.2.tar.gz.

File metadata

  • Download URL: ethiotime-1.0.2.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for ethiotime-1.0.2.tar.gz
Algorithm Hash digest
SHA256 6f283ba536edaff3718c228ebdcbd9b007b6c418013e89b149b7391b8738ffae
MD5 a8d35be0b578ae3aebe8cb39150d4f02
BLAKE2b-256 8b891462985c7d7ce0b2c8107abedb642faa43a792023fc14c4bfc03f094574c

See more details on using hashes here.

File details

Details for the file ethiotime-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: ethiotime-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for ethiotime-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 911c8739177fd761ce15e2acd549464a98108032fd4409d85ff4dab40f33cf92
MD5 d9032f0db7a95f2e1068919d2a679c20
BLAKE2b-256 12535ca8353ad206d0daba1be73ec6742de75cbfa3b37b8e7b840d790043491a

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