kenat 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kenat/__init__.py +24 -0
- kenat/bahire_hasab.py +133 -0
- kenat/constants.py +185 -0
- kenat/conversions.py +148 -0
- kenat/day_arithmetic.py +150 -0
- kenat/exceptions.py +63 -0
- kenat/formatting.py +67 -0
- kenat/geez_converter.py +112 -0
- kenat/holidays.py +171 -0
- kenat/kenat.py +281 -0
- kenat/month_grid.py +106 -0
- kenat/time.py +196 -0
- kenat/utils.py +104 -0
- kenat-1.0.0.dist-info/METADATA +206 -0
- kenat-1.0.0.dist-info/RECORD +18 -0
- kenat-1.0.0.dist-info/WHEEL +5 -0
- kenat-1.0.0.dist-info/licenses/LICENSE +21 -0
- kenat-1.0.0.dist-info/top_level.txt +1 -0
kenat/__init__.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from .kenat import Kenat
|
|
2
|
+
from .conversions import to_ec, to_gc
|
|
3
|
+
from .geez_converter import to_arabic, to_geez
|
|
4
|
+
from .holidays import get_holidays_in_month, get_holiday, get_holidays_for_year
|
|
5
|
+
from .bahire_hasab import get_bahire_hasab
|
|
6
|
+
from .month_grid import MonthGrid
|
|
7
|
+
from .time import Time
|
|
8
|
+
from .constants import HolidayTags, MONTH_NAMES
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
'Kenat',
|
|
12
|
+
'to_ec',
|
|
13
|
+
'to_gc',
|
|
14
|
+
'to_arabic',
|
|
15
|
+
'to_geez',
|
|
16
|
+
'get_holidays_in_month',
|
|
17
|
+
'get_holidays_for_year',
|
|
18
|
+
'get_bahire_hasab',
|
|
19
|
+
'MonthGrid',
|
|
20
|
+
'Time',
|
|
21
|
+
'get_holiday',
|
|
22
|
+
'HolidayTags',
|
|
23
|
+
'MONTH_NAMES',
|
|
24
|
+
]
|
kenat/bahire_hasab.py
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
from .utils import validate_numeric_inputs, get_weekday
|
|
2
|
+
from .day_arithmetic import add_days
|
|
3
|
+
from .conversions import to_gc
|
|
4
|
+
from .exceptions import UnknownHolidayError
|
|
5
|
+
from .constants import (
|
|
6
|
+
DAYS_OF_WEEK,
|
|
7
|
+
EVANGELIST_NAMES,
|
|
8
|
+
TEWSAK_MAP,
|
|
9
|
+
MOVABLE_HOLIDAY_TEWSAK,
|
|
10
|
+
KEY_TO_TEWSAK_MAP,
|
|
11
|
+
HOLIDAY_INFO,
|
|
12
|
+
MOVABLE_HOLIDAYS
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
def _calculate_bahire_hasab_base(ethiopian_year):
|
|
16
|
+
"""
|
|
17
|
+
Calculates and returns all base values for the Bahire Hasab system.
|
|
18
|
+
This internal helper is the single source of truth for the core computational logic.
|
|
19
|
+
"""
|
|
20
|
+
amete_alem = 5500 + ethiopian_year
|
|
21
|
+
metene_rabiet = amete_alem // 4
|
|
22
|
+
medeb = amete_alem % 19
|
|
23
|
+
wenber = 18 if medeb == 0 else medeb - 1
|
|
24
|
+
abektie = (wenber * 11) % 30
|
|
25
|
+
metqi = (wenber * 19) % 30
|
|
26
|
+
|
|
27
|
+
beale_metqi_month = 1 if metqi > 14 else 2
|
|
28
|
+
beale_metqi_day = metqi
|
|
29
|
+
beale_metqi_date = {'year': ethiopian_year, 'month': beale_metqi_month, 'day': beale_metqi_day}
|
|
30
|
+
|
|
31
|
+
beale_metqi_weekday = DAYS_OF_WEEK['english'][get_weekday(beale_metqi_date)]
|
|
32
|
+
tewsak = TEWSAK_MAP[beale_metqi_weekday]
|
|
33
|
+
|
|
34
|
+
mebaja_hamer_sum = beale_metqi_day + tewsak
|
|
35
|
+
mebaja_hamer = mebaja_hamer_sum % 30 if mebaja_hamer_sum > 30 else mebaja_hamer_sum
|
|
36
|
+
|
|
37
|
+
nineveh_month = 5 if metqi > 14 else 6
|
|
38
|
+
if mebaja_hamer_sum > 30:
|
|
39
|
+
nineveh_month += 1
|
|
40
|
+
|
|
41
|
+
nineveh_date = {'year': ethiopian_year, 'month': nineveh_month, 'day': mebaja_hamer}
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
'amete_alem': amete_alem,
|
|
45
|
+
'metene_rabiet': metene_rabiet,
|
|
46
|
+
'medeb': medeb,
|
|
47
|
+
'wenber': wenber,
|
|
48
|
+
'abektie': abektie,
|
|
49
|
+
'metqi': metqi,
|
|
50
|
+
'beale_metqi_date': beale_metqi_date,
|
|
51
|
+
'beale_metqi_weekday': beale_metqi_weekday,
|
|
52
|
+
'mebaja_hamer': mebaja_hamer,
|
|
53
|
+
'nineveh_date': nineveh_date,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
def get_bahire_hasab(ethiopian_year, lang='amharic'):
|
|
57
|
+
"""
|
|
58
|
+
Calculates all Bahire Hasab values for a given Ethiopian year.
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
ethiopian_year (int): The Ethiopian year to calculate for.
|
|
62
|
+
lang (str): The language for names ('amharic' or 'english').
|
|
63
|
+
|
|
64
|
+
Returns:
|
|
65
|
+
dict: An object containing all the calculated Bahire Hasab values.
|
|
66
|
+
"""
|
|
67
|
+
validate_numeric_inputs('get_bahire_hasab', ethiopian_year=ethiopian_year)
|
|
68
|
+
|
|
69
|
+
base = _calculate_bahire_hasab_base(ethiopian_year)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
evangelist_remainder = base['amete_alem'] % 4
|
|
73
|
+
evangelist_name = EVANGELIST_NAMES.get(lang, EVANGELIST_NAMES['english'])[evangelist_remainder]
|
|
74
|
+
|
|
75
|
+
tinte_qemer = (base['amete_alem'] + base['metene_rabiet']) % 7
|
|
76
|
+
weekday_index = (tinte_qemer + 1) % 7
|
|
77
|
+
new_year_weekday = DAYS_OF_WEEK.get(lang, DAYS_OF_WEEK['english'])[weekday_index]
|
|
78
|
+
|
|
79
|
+
movable_feasts = {}
|
|
80
|
+
tewsak_to_key_map = {v: k for k, v in KEY_TO_TEWSAK_MAP.items()}
|
|
81
|
+
|
|
82
|
+
for tewsak_key, tewsak_value in MOVABLE_HOLIDAY_TEWSAK.items():
|
|
83
|
+
holiday_key = tewsak_to_key_map.get(tewsak_key)
|
|
84
|
+
if holiday_key:
|
|
85
|
+
date = add_days(base['nineveh_date'], tewsak_value)
|
|
86
|
+
info = HOLIDAY_INFO.get(holiday_key, {})
|
|
87
|
+
rules = MOVABLE_HOLIDAYS.get(holiday_key, {})
|
|
88
|
+
|
|
89
|
+
movable_feasts[holiday_key] = {
|
|
90
|
+
'key': holiday_key,
|
|
91
|
+
'tags': rules.get('tags', []),
|
|
92
|
+
'movable': True,
|
|
93
|
+
'name': info.get('name', {}).get(lang) or info.get('name', {}).get('english'),
|
|
94
|
+
'description': info.get('description', {}).get(lang) or info.get('description', {}).get('english'),
|
|
95
|
+
'ethiopian': date,
|
|
96
|
+
'gregorian': to_gc(date['year'], date['month'], date['day'])
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
'ameteAlem': base['amete_alem'],
|
|
101
|
+
'meteneRabiet': base['metene_rabiet'],
|
|
102
|
+
'evangelist': {'name': evangelist_name, 'remainder': evangelist_remainder},
|
|
103
|
+
'newYear': {'dayName': new_year_weekday, 'tinteQemer': tinte_qemer},
|
|
104
|
+
'medeb': base['medeb'],
|
|
105
|
+
'wenber': base['wenber'],
|
|
106
|
+
'abektie': base['abektie'],
|
|
107
|
+
'metqi': base['metqi'],
|
|
108
|
+
'bealeMetqi': {'date': base['beale_metqi_date'], 'weekday': base['beale_metqi_weekday']},
|
|
109
|
+
'mebajaHamer': base['mebaja_hamer'],
|
|
110
|
+
'nineveh': base['nineveh_date'],
|
|
111
|
+
'movableFeasts': movable_feasts
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
def get_movable_holiday(holiday_key, ethiopian_year):
|
|
115
|
+
"""
|
|
116
|
+
Calculates the date of a movable holiday for a given year.
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
holiday_key (str): The key of the holiday (e.g., 'ABIY_TSOME', 'TINSAYE').
|
|
120
|
+
ethiopian_year (int): The Ethiopian year.
|
|
121
|
+
|
|
122
|
+
Returns:
|
|
123
|
+
dict: An Ethiopian date object {'year', 'month', 'day'}.
|
|
124
|
+
"""
|
|
125
|
+
validate_numeric_inputs('get_movable_holiday', ethiopian_year=ethiopian_year)
|
|
126
|
+
|
|
127
|
+
tewsak = MOVABLE_HOLIDAY_TEWSAK.get(holiday_key)
|
|
128
|
+
if tewsak is None:
|
|
129
|
+
raise UnknownHolidayError(holiday_key)
|
|
130
|
+
|
|
131
|
+
base = _calculate_bahire_hasab_base(ethiopian_year)
|
|
132
|
+
|
|
133
|
+
return add_days(base['nineveh_date'], tewsak)
|
kenat/constants.py
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
MONTH_NAMES = {
|
|
2
|
+
"english": [
|
|
3
|
+
"Meskerem", "Tikimt", "Hidar", "Tahsas", "Tir", "Yekatit",
|
|
4
|
+
"Megabit", "Miazia", "Ginbot", "Sene", "Hamle", "Nehase", "Pagume"
|
|
5
|
+
],
|
|
6
|
+
"amharic": [
|
|
7
|
+
"መስከረም", "ጥቅምት", "ህዳር", "ታህሳስ", "ጥር", "የካቲት",
|
|
8
|
+
"መጋቢት", "ሚያዝያ", "ግንቦት", "ሰኔ", "ሀምሌ", "ነሐሴ", "ጳጉሜ"
|
|
9
|
+
],
|
|
10
|
+
"gregorian": [
|
|
11
|
+
"January", "February", "March", "April", "May", "June",
|
|
12
|
+
"July", "August", "September", "October", "November", "December"
|
|
13
|
+
],
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
DAYS_OF_WEEK = {
|
|
17
|
+
"english": [
|
|
18
|
+
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
|
|
19
|
+
],
|
|
20
|
+
"amharic": [
|
|
21
|
+
"እሑድ", "ሰኞ", "ማክሰኞ", "ረቡዕ", "ሐሙስ", "ዓርብ", "ቅዳሜ"
|
|
22
|
+
],
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
class HolidayTags:
|
|
26
|
+
PUBLIC = "public"
|
|
27
|
+
RELIGIOUS = "religious"
|
|
28
|
+
CHRISTIAN = "christian"
|
|
29
|
+
MUSLIM = "muslim"
|
|
30
|
+
STATE = "state"
|
|
31
|
+
CULTURAL = "cultural"
|
|
32
|
+
OTHER = "other"
|
|
33
|
+
|
|
34
|
+
KEY_TO_TEWSAK_MAP = {
|
|
35
|
+
'nineveh': 'NINEVEH', 'abiyTsome': 'ABIY_TSOME', 'debreZeit': 'DEBRE_ZEIT',
|
|
36
|
+
'hosanna': 'HOSANNA', 'siklet': 'SIKLET', 'fasika': 'TINSAYE',
|
|
37
|
+
'rikbeKahnat': 'RIKBE_KAHNAT', 'erget': 'ERGET', 'paraclete': 'PARACLETE',
|
|
38
|
+
'tsomeHawaryat': 'TSOME_HAWARYAT', 'tsomeDihnet': 'TSOME_DIHENET'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
PERIOD_LABELS = {
|
|
42
|
+
'day': 'ጠዋት',
|
|
43
|
+
'night': 'ማታ',
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
# Holiday names and descriptions, structured for internationalization (i18n)
|
|
47
|
+
HOLIDAY_INFO = {
|
|
48
|
+
'enkutatash': {
|
|
49
|
+
'name': {'amharic': 'እንቁጣጣሽ', 'english': 'Ethiopian New Year (Enkutatash)'},
|
|
50
|
+
'description': {'amharic': 'የኢትዮጵያ አዲስ ዓመት መጀመሪያ፤\nየዝናብ ወቅት ማብቃቱን እና ዳግም መታደስን ያመለክታል።', 'english': 'Marks the start of the Ethiopian year;\nsymbolizes renewal and the end of the rainy season.'}
|
|
51
|
+
},
|
|
52
|
+
'meskel': {
|
|
53
|
+
'name': {'amharic': 'መስቀል', 'english': 'Finding of the True Cross (Meskel)'},
|
|
54
|
+
'description': {'amharic': 'በ4ኛው መቶ ክፍለ ዘመን በንግሥት እሌኒ አማካኝነት የጌታችን መስቀል መገኘቱን ያከብራል።', 'english': 'Commemorates the discovery of the True Cross by Empress Helena in the 4th century.'}
|
|
55
|
+
},
|
|
56
|
+
'beherbehereseb': {
|
|
57
|
+
'name': {'amharic': 'የብሔር ብሔረሰቦች ቀን', 'english': 'Nations, Nationalities, and Peoples\' Day'},
|
|
58
|
+
'description': {'amharic': 'የኢትዮጵያ ብሔር ብሔረሰቦችን ልዩነት የሚያከብር፣ እኩል መብታቸውን የሚያረጋግጥ እና በባህልና ቋንቋ አንድነትን የሚያጠናክር በዓል ነው።', 'english': 'Acknowledges and celebrates the diversity of Ethiopia\'s ethnic groups, affirming their equal rights and fostering unity.'}
|
|
59
|
+
},
|
|
60
|
+
'gena': {
|
|
61
|
+
'name': {'amharic': 'ገና', 'english': 'Ethiopian Christmas (Genna)'},
|
|
62
|
+
'description': {'amharic': 'የኢየሱስ ክርስቶስን ልደት የሚያከብር የኢትዮጵያ ኦርቶዶክስ ተዋሕዶ ቤተ ክርስቲያን በዓል።', 'english': 'Ethiopian Orthodox Christmas celebrating the birth of Jesus Christ.'}
|
|
63
|
+
},
|
|
64
|
+
'timket': {
|
|
65
|
+
'name': {'amharic': 'ጥምቀት', 'english': 'Ethiopian Epiphany (Timket)'},
|
|
66
|
+
'description': {'amharic': 'የኢየሱስ ክርስቶስን በዮርዳኖስ ወንዝ መጠመቁን ያከብራል።', 'english': 'Commemorates the baptism of Jesus in the Jordan River.'}
|
|
67
|
+
},
|
|
68
|
+
'martyrsDay': {
|
|
69
|
+
'name': {'amharic': 'የሰማዕታት ቀን', 'english': 'Martyrs\' Day'},
|
|
70
|
+
'description': {'amharic': 'ለኢትዮጵያ ነፃነትና ክብር ሕይወታቸውን የሠዉ ሰማዕታትን ያስባል።', 'english': 'Honors those who sacrificed their lives for Ethiopia’s freedom and independence.'}
|
|
71
|
+
},
|
|
72
|
+
'adwa': {
|
|
73
|
+
'name': {'amharic': 'የአድዋ ድል በዓል', 'english': 'Victory of Adwa'},
|
|
74
|
+
'description': {'amharic': 'በ1896 ዓ.ም.\nኢትዮጵያ በጣሊያን ቅኝ ገዥዎች ላይ የተቀዳጀችውን ድል ያከብራል።', 'english': 'Celebrates Ethiopia’s victory over Italian colonizers in 1896.'}
|
|
75
|
+
},
|
|
76
|
+
'labour': {
|
|
77
|
+
'name': {'amharic': 'የሰራተኞች ቀን', 'english': 'International Labour Day'},
|
|
78
|
+
'description': {'amharic': 'ዓለም አቀፍ የሠራተኞችና የሥራ መብቶች ቀን ነው።', 'english': 'A global celebration of workers and labor rights.'}
|
|
79
|
+
},
|
|
80
|
+
'patriots': {
|
|
81
|
+
'name': {'amharic': 'የአርበኞች ቀን', 'english': 'Patriots\' Victory Day'},
|
|
82
|
+
'description': {'amharic': 'የጣሊያን ወረራን የተቋቋሙ ኢትዮጵያውያን አርበኞችን ድል ያስባል።', 'english': 'Honors Ethiopian resistance fighters who defeated Italian occupation.'}
|
|
83
|
+
},
|
|
84
|
+
'nineveh': {
|
|
85
|
+
'name': {'amharic': 'ጾመ ነነዌ', 'english': 'Fast of Nineveh'},
|
|
86
|
+
'description': {'amharic': 'የነነዌ ሰዎች ንስሐ መግባታቸውን የሚያስታውስ የሦስት ቀን ጾም ነው።', 'english': 'A three-day fast commemorating the repentance of the people of Nineveh.'}
|
|
87
|
+
},
|
|
88
|
+
'abiyTsome': {
|
|
89
|
+
'name': {'amharic': 'ዐቢይ ጾም', 'english': 'Great Lent'},
|
|
90
|
+
'description': {'amharic': 'ከፋሲካ በፊት የሚጾም የ55 ቀናት የጾም ወቅት ነው።', 'english': 'The Great Lent, a 55-day fasting period before Easter.'}
|
|
91
|
+
},
|
|
92
|
+
'debreZeit': {
|
|
93
|
+
'name': {'amharic': 'ደብረ ዘይት', 'english': 'Mid-Lent Sunday'},
|
|
94
|
+
'description': {'amharic': 'ኢየሱስ በደብረ ዘይት ተራራ ያስተማረውን ትምህርት የሚያስታውስ የዐቢይ ጾም አጋማሽ እሑድ።', 'english': 'Mid-Lent Sunday, commemorating Jesus\'s sermon on the Mount of Olives.'}
|
|
95
|
+
},
|
|
96
|
+
'hosanna': {
|
|
97
|
+
'name': {'amharic': 'ሆሳዕና', 'english': 'Palm Sunday'},
|
|
98
|
+
'description': {'amharic': 'ኢየሱስ በክብር ወደ ኢየሩሳሌም መግባቱን የሚያስታውስ በዓል።', 'english': 'Palm Sunday, commemorating Jesus\'s triumphal entry into Jerusalem.'}
|
|
99
|
+
},
|
|
100
|
+
'siklet': {
|
|
101
|
+
'name': {'amharic': 'ስቅለት', 'english': 'Good Friday'},
|
|
102
|
+
'description': {'amharic': 'የኢየሱስ ክርስቶስን ስቅለት የሚያስታውስ ነው።', 'english': 'Marks the crucifixion of Jesus Christ.'}
|
|
103
|
+
},
|
|
104
|
+
'fasika': {
|
|
105
|
+
'name': {'amharic': 'ፋሲካ', 'english': 'Ethiopian Easter'},
|
|
106
|
+
'description': {'amharic': 'የኢየሱስ ክርስቶስን ከሙታን መነሣት ያከብራል።\nበኢትዮጵያ ውስጥ ካሉ ክርስቲያናዊ በዓላት አንዱና ዋነኛው ነው።', 'english': 'Celebrates the resurrection of Jesus Christ.\nOne of the most important Christian holidays in Ethiopia.'}
|
|
107
|
+
},
|
|
108
|
+
'rikbeKahnat': {
|
|
109
|
+
'name': {'amharic': 'ርክበ ካህናት', 'english': 'Meeting of the Priests'},
|
|
110
|
+
'description': {'amharic': 'ከፋሲካ 24 ቀናት በኋላ የሚከበር የካህናት መሰባሰብ በዓል ነው።', 'english': 'The Meeting of the Priests, 24 days after Easter.'}
|
|
111
|
+
},
|
|
112
|
+
'erget': {
|
|
113
|
+
'name': {'amharic': 'ዕርገት', 'english': 'Ascension'},
|
|
114
|
+
'description': {'amharic': 'ከፋሲካ 40 ቀናት በኋላ ኢየሱስ ወደ ሰማይ ማረጉን ያከብራል።', 'english': 'The Ascension of Jesus into heaven, 40 days after Easter.'}
|
|
115
|
+
},
|
|
116
|
+
'paraclete': {
|
|
117
|
+
'name': {'amharic': 'ጰራቅሊጦስ', 'english': 'Pentecost'},
|
|
118
|
+
'description': {'amharic': 'መንፈስ ቅዱስ በሐዋርያት ላይ መውረዱን የሚያከብር በዓል፣ ከፋሲካ 50 ቀናት በኋላ።', 'english': 'Pentecost, celebrating the descent of the Holy Spirit upon the Apostles, 50 days after Easter.'}
|
|
119
|
+
},
|
|
120
|
+
'tsomeHawaryat': {
|
|
121
|
+
'name': {'amharic': 'ጾመ ሐዋርያት', 'english': 'Apostles\' Fast'},
|
|
122
|
+
'description': {'amharic': 'ከጰራቅሊጦስ ማግስት የሚጀምር የሐዋርያት ጾም ነው።', 'english': 'The Fast of the Apostles, which begins the day after Pentecost.'}
|
|
123
|
+
},
|
|
124
|
+
'tsomeDihnet': {
|
|
125
|
+
'name': {'amharic': 'ጾመ ድኅነት', 'english': 'Fast of Salvation'},
|
|
126
|
+
'description': {'amharic': 'በየሳምንቱ ረቡዕ እና ዓርብ የሚጾም የድኅነት ጾም ነው።', 'english': 'The Fast of Salvation, observed on Wednesdays and Fridays.'}
|
|
127
|
+
},
|
|
128
|
+
'eidFitr': {
|
|
129
|
+
'name': {'amharic': 'ዒድ አል ፈጥር', 'english': 'Eid al-Fitr'},
|
|
130
|
+
'description': {'amharic': 'የረመዳን ጾም ወር መገባደድን የሚያመለክት በዓል።', 'english': 'Marks the end of Ramadan, the month of fasting for Muslims.'}
|
|
131
|
+
},
|
|
132
|
+
'eidAdha': {
|
|
133
|
+
'name': {'amharic': 'ዒድ አል አድሐ', 'english': 'Eid al-Adha'},
|
|
134
|
+
'description': {'amharic': 'አብርሃም ለእግዚአብሔር በመታዘዝ ልጁን ለመሠዋት ፈቃደኝነቱን የሚያስታውስ በዓል።', 'english': 'Commemorates Abraham’s willingness to sacrifice his son as an act of obedience to God.'}
|
|
135
|
+
},
|
|
136
|
+
'moulid': {
|
|
137
|
+
'name': {'amharic': 'መውሊድ', 'english': 'Birth of the Prophet'},
|
|
138
|
+
'description': {'amharic': 'የነቢዩ ሙሐመድን የልደት በዓል ያከብራል።', 'english': 'Celebrates the birthday of the Prophet Mohammed.'}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
# Bahire Hasab related constants
|
|
143
|
+
EVANGELIST_NAMES = {
|
|
144
|
+
'english': { 1: 'Matthew', 2: 'Mark', 3: 'Luke', 0: 'John' },
|
|
145
|
+
'amharic': { 1: 'ማቴዎስ', 2: 'ማርቆስ', 3: 'ሉቃስ', 0: 'ዮሐንስ' }
|
|
146
|
+
}
|
|
147
|
+
TEWSAK_MAP = {
|
|
148
|
+
'Sunday': 7, 'Monday': 6, 'Tuesday': 5, 'Wednesday': 4, 'Thursday': 3, 'Friday': 2, 'Saturday': 8
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
MOVABLE_HOLIDAY_TEWSAK = {
|
|
152
|
+
'NINEVEH': 0, 'ABIY_TSOME': 14, 'DEBRE_ZEIT': 41, 'HOSANNA': 62, 'SIKLET': 67, 'TINSAYE': 69,
|
|
153
|
+
'RIKBE_KAHNAT': 93, 'ERGET': 108, 'PARACLETE': 118, 'TSOME_HAWARYAT': 119, 'TSOME_DIHENET': 121,
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
# Tags associated with movable holidays
|
|
157
|
+
MOVABLE_HOLIDAYS = {
|
|
158
|
+
'nineveh': {'tags': [HolidayTags.RELIGIOUS, HolidayTags.CHRISTIAN]},
|
|
159
|
+
'abiyTsome': {'tags': [HolidayTags.RELIGIOUS, HolidayTags.CHRISTIAN]},
|
|
160
|
+
'debreZeit': {'tags': [HolidayTags.RELIGIOUS, HolidayTags.CHRISTIAN]},
|
|
161
|
+
'hosanna': {'tags': [HolidayTags.RELIGIOUS, HolidayTags.CHRISTIAN]},
|
|
162
|
+
'siklet': {'tags': [HolidayTags.RELIGIOUS, HolidayTags.CHRISTIAN]},
|
|
163
|
+
'fasika': {'tags': [HolidayTags.PUBLIC, HolidayTags.RELIGIOUS, HolidayTags.CHRISTIAN]},
|
|
164
|
+
'rikbeKahnat': {'tags': [HolidayTags.RELIGIOUS, HolidayTags.CHRISTIAN]},
|
|
165
|
+
'erget': {'tags': [HolidayTags.RELIGIOUS, HolidayTags.CHRISTIAN]},
|
|
166
|
+
'paraclete': {'tags': [HolidayTags.RELIGIOUS, HolidayTags.CHRISTIAN]},
|
|
167
|
+
'tsomeHawaryat': {'tags': [HolidayTags.RELIGIOUS, HolidayTags.CHRISTIAN]},
|
|
168
|
+
'tsomeDihnet': {'tags': [HolidayTags.RELIGIOUS, HolidayTags.CHRISTIAN]},
|
|
169
|
+
'eidFitr': {'tags': [HolidayTags.PUBLIC, HolidayTags.RELIGIOUS, HolidayTags.MUSLIM]},
|
|
170
|
+
'eidAdha': {'tags': [HolidayTags.PUBLIC, HolidayTags.RELIGIOUS, HolidayTags.MUSLIM]},
|
|
171
|
+
'moulid': {'tags': [HolidayTags.PUBLIC, HolidayTags.RELIGIOUS, HolidayTags.MUSLIM]},
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
# Fixed holidays with their specific dates and tags
|
|
175
|
+
FIXED_HOLIDAYS = {
|
|
176
|
+
'enkutatash': { 'month': 1, 'day': 1, 'tags': [HolidayTags.PUBLIC, HolidayTags.CULTURAL] },
|
|
177
|
+
'meskel': { 'month': 1, 'day': 17, 'tags': [HolidayTags.PUBLIC, HolidayTags.RELIGIOUS, HolidayTags.CHRISTIAN] },
|
|
178
|
+
'beherbehereseb': { 'month': 3, 'day': 20, 'tags': [HolidayTags.PUBLIC, HolidayTags.STATE] },
|
|
179
|
+
'gena': { 'month': 4, 'day': 29, 'tags': [HolidayTags.PUBLIC, HolidayTags.RELIGIOUS, HolidayTags.CHRISTIAN] },
|
|
180
|
+
'timket': { 'month': 5, 'day': 11, 'tags': [HolidayTags.PUBLIC, HolidayTags.RELIGIOUS, HolidayTags.CHRISTIAN] },
|
|
181
|
+
'martyrsDay': { 'month': 6, 'day': 12, 'tags': [HolidayTags.PUBLIC, HolidayTags.STATE] },
|
|
182
|
+
'adwa': { 'month': 6, 'day': 23, 'tags': [HolidayTags.PUBLIC, HolidayTags.STATE] },
|
|
183
|
+
'labour': { 'month': 8, 'day': 23, 'tags': [HolidayTags.PUBLIC, HolidayTags.STATE] },
|
|
184
|
+
'patriots': { 'month': 8, 'day': 27, 'tags': [HolidayTags.PUBLIC, HolidayTags.STATE] },
|
|
185
|
+
}
|
kenat/conversions.py
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
import math
|
|
3
|
+
from .utils import (
|
|
4
|
+
is_gregorian_leap_year,
|
|
5
|
+
is_ethiopian_leap_year,
|
|
6
|
+
get_ethiopian_days_in_month,
|
|
7
|
+
validate_numeric_inputs
|
|
8
|
+
)
|
|
9
|
+
from .exceptions import InvalidEthiopianDateError, InvalidGregorianDateError, KenatError
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def to_gc(eth_year, eth_month, eth_day):
|
|
13
|
+
"""
|
|
14
|
+
Converts an Ethiopian date to its corresponding Gregorian date.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
eth_year (int): The Ethiopian year.
|
|
18
|
+
eth_month (int): The Ethiopian month (1-13).
|
|
19
|
+
eth_day (int): The Ethiopian day.
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
datetime.date: The equivalent Gregorian date object.
|
|
23
|
+
"""
|
|
24
|
+
# 1. Validate input types and date range
|
|
25
|
+
validate_numeric_inputs('to_gc', eth_year=eth_year, eth_month=eth_month, eth_day=eth_day)
|
|
26
|
+
if not 1 <= eth_month <= 13 or not 1 <= eth_day <= get_ethiopian_days_in_month(eth_year, eth_month):
|
|
27
|
+
raise InvalidEthiopianDateError(eth_year, eth_month, eth_day)
|
|
28
|
+
|
|
29
|
+
# 2. Determine the Gregorian date of the Ethiopian New Year
|
|
30
|
+
gregorian_year = eth_year + 7
|
|
31
|
+
new_year_day = 12 if is_gregorian_leap_year(gregorian_year + 1) else 11
|
|
32
|
+
new_year_date = datetime.date(gregorian_year, 9, new_year_day)
|
|
33
|
+
|
|
34
|
+
# 3. Calculate days elapsed since the Ethiopian new year and add to the new year date
|
|
35
|
+
days_to_add = (eth_month - 1) * 30 + (eth_day - 1)
|
|
36
|
+
|
|
37
|
+
return new_year_date + datetime.timedelta(days=days_to_add)
|
|
38
|
+
|
|
39
|
+
def to_ec(greg_year, greg_month, greg_day):
|
|
40
|
+
"""
|
|
41
|
+
Converts a Gregorian date to the Ethiopian calendar (EC) date.
|
|
42
|
+
"""
|
|
43
|
+
# 1. Validate input types
|
|
44
|
+
validate_numeric_inputs('to_ec', g_year=greg_year, g_month=greg_month, g_day=greg_day)
|
|
45
|
+
|
|
46
|
+
# 2. Validate date validity and range (1900-2100) to match original library
|
|
47
|
+
try:
|
|
48
|
+
greg_date = datetime.date(greg_year, greg_month, greg_day)
|
|
49
|
+
if not (datetime.date(1900, 1, 1) <= greg_date <= datetime.date(2100, 12, 31)):
|
|
50
|
+
raise InvalidGregorianDateError(greg_year, greg_month, greg_day)
|
|
51
|
+
except (ValueError, InvalidGregorianDateError): # Catch both invalid dates and out-of-range
|
|
52
|
+
raise InvalidGregorianDateError(greg_year, greg_month, greg_day)
|
|
53
|
+
|
|
54
|
+
# 3. Determine the corresponding Ethiopian year
|
|
55
|
+
eth_year = greg_year - 8
|
|
56
|
+
greg_of_eth_new_year = to_gc(eth_year + 1, 1, 1)
|
|
57
|
+
if greg_date >= greg_of_eth_new_year:
|
|
58
|
+
eth_year += 1
|
|
59
|
+
|
|
60
|
+
# 4. Calculate the difference in days from that Ethiopian New Year
|
|
61
|
+
new_year_greg_date = to_gc(eth_year, 1, 1)
|
|
62
|
+
days_diff = (greg_date - new_year_greg_date).days
|
|
63
|
+
|
|
64
|
+
# 5. Convert the day difference into Ethiopian month and day
|
|
65
|
+
eth_month = (days_diff // 30) + 1
|
|
66
|
+
eth_day = (days_diff % 30) + 1
|
|
67
|
+
|
|
68
|
+
return {'year': eth_year, 'month': eth_month, 'day': eth_day}
|
|
69
|
+
|
|
70
|
+
def _gregorian_to_jd(year, month, day):
|
|
71
|
+
"""Converts a Gregorian date to Julian Day Number."""
|
|
72
|
+
if month < 3:
|
|
73
|
+
year -= 1
|
|
74
|
+
month += 12
|
|
75
|
+
a = year // 100
|
|
76
|
+
b = a // 4
|
|
77
|
+
c = 2 - a + b
|
|
78
|
+
e = int(365.25 * (year + 4716))
|
|
79
|
+
f = int(30.6001 * (month + 1))
|
|
80
|
+
return c + day + e + f - 1524
|
|
81
|
+
|
|
82
|
+
def _jd_to_gregorian(jd):
|
|
83
|
+
"""Converts a Julian Day Number to a Gregorian date."""
|
|
84
|
+
q = jd + 0.5
|
|
85
|
+
z = int(q)
|
|
86
|
+
w = (z - 1867216.25) / 36524.25
|
|
87
|
+
x = w // 4
|
|
88
|
+
a = z + 1 + w - x
|
|
89
|
+
b = a + 1524
|
|
90
|
+
c = (b - 122.1) / 365.25
|
|
91
|
+
d = int(c)
|
|
92
|
+
e = int(365.25 * d)
|
|
93
|
+
f = int((b - e) / 30.6001)
|
|
94
|
+
day = b - e - int(30.6001 * f)
|
|
95
|
+
month = f - 1 if f < 14 else f - 13
|
|
96
|
+
year = d - 4716 if month > 2 else d - 4715
|
|
97
|
+
return datetime.date(year, month, day)
|
|
98
|
+
|
|
99
|
+
def _hijri_to_jd(year, month, day):
|
|
100
|
+
"""Converts a Hijri date to Julian Day Number."""
|
|
101
|
+
# This is the corrected formula for the Tabular Islamic Calendar.
|
|
102
|
+
return int((11 * year + 3) / 30) + 354 * year + 30 * month - int((month - 1) / 2) + day + 1948440 - 385
|
|
103
|
+
|
|
104
|
+
def _jd_to_hijri(jd):
|
|
105
|
+
"""Converts a Julian Day Number to a Hijri date using the tabular Islamic calendar."""
|
|
106
|
+
jd = math.floor(jd) + 0.5 # Ensure it's at start of day
|
|
107
|
+
jd = jd - 1948439.5
|
|
108
|
+
year = int((30 * jd + 10646) // 10631)
|
|
109
|
+
start_of_year = 354 * (year - 1) + math.floor((3 + 11 * year) / 30)
|
|
110
|
+
day_of_year = int(jd - start_of_year)
|
|
111
|
+
month = int((day_of_year) // 29.5) + 1
|
|
112
|
+
if month > 12:
|
|
113
|
+
month = 12
|
|
114
|
+
start_of_month = 29.5 * (month - 1)
|
|
115
|
+
day = int(jd - (start_of_year + start_of_month)) + 1
|
|
116
|
+
return {'year': year, 'month': month, 'day': day}
|
|
117
|
+
|
|
118
|
+
def hijri_to_gregorian(h_year, h_month, h_day, gregorian_year):
|
|
119
|
+
"""
|
|
120
|
+
Converts a Hijri date to a Gregorian date by searching within a given Gregorian year.
|
|
121
|
+
This mimics the brute-force search methodology of the original JavaScript code.
|
|
122
|
+
"""
|
|
123
|
+
# Start searching from the beginning of the previous Gregorian year to be safe.
|
|
124
|
+
base_date = datetime.date(gregorian_year - 1, 1, 1)
|
|
125
|
+
|
|
126
|
+
# Search for up to 730 days (2 years) to guarantee finding the date.
|
|
127
|
+
for offset in range(731):
|
|
128
|
+
test_date = base_date + datetime.timedelta(days=offset)
|
|
129
|
+
|
|
130
|
+
# For each day, find its corresponding Hijri date using our JDN functions.
|
|
131
|
+
jd = _gregorian_to_jd(test_date.year, test_date.month, test_date.day)
|
|
132
|
+
hijri_parts = _jd_to_hijri(jd)
|
|
133
|
+
|
|
134
|
+
# Check if we have a match for the target date within the target year.
|
|
135
|
+
if (
|
|
136
|
+
hijri_parts['year'] == h_year and
|
|
137
|
+
hijri_parts['month'] == h_month and
|
|
138
|
+
hijri_parts['day'] == h_day and
|
|
139
|
+
test_date.year == gregorian_year
|
|
140
|
+
):
|
|
141
|
+
return test_date # Found it!
|
|
142
|
+
|
|
143
|
+
return None
|
|
144
|
+
|
|
145
|
+
def get_hijri_year(greg_date):
|
|
146
|
+
"""Gets the Hijri year from a Gregorian date object."""
|
|
147
|
+
jd = _gregorian_to_jd(greg_date.year, greg_date.month, greg_date.day)
|
|
148
|
+
return _jd_to_hijri(jd)['year']
|
kenat/day_arithmetic.py
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
from .utils import (
|
|
2
|
+
get_ethiopian_days_in_month,
|
|
3
|
+
is_ethiopian_leap_year,
|
|
4
|
+
validate_numeric_inputs,
|
|
5
|
+
validate_ethiopian_date_object
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
def add_days(ethiopian, days):
|
|
9
|
+
"""
|
|
10
|
+
Adds a specified number of days to an Ethiopian date.
|
|
11
|
+
|
|
12
|
+
Args:
|
|
13
|
+
ethiopian (dict): The starting Ethiopian date {'year', 'month', 'day'}.
|
|
14
|
+
days (int): The number of days to add.
|
|
15
|
+
|
|
16
|
+
Returns:
|
|
17
|
+
dict: The resulting Ethiopian date.
|
|
18
|
+
"""
|
|
19
|
+
validate_ethiopian_date_object(ethiopian, 'add_days', 'ethiopian') #
|
|
20
|
+
validate_numeric_inputs('add_days', days=days) #
|
|
21
|
+
|
|
22
|
+
# Create mutable copies
|
|
23
|
+
year, month, day = ethiopian['year'], ethiopian['month'], ethiopian['day']
|
|
24
|
+
day += days
|
|
25
|
+
|
|
26
|
+
# Roll over the days into months and years
|
|
27
|
+
while day > get_ethiopian_days_in_month(year, month): #
|
|
28
|
+
day -= get_ethiopian_days_in_month(year, month) #
|
|
29
|
+
month += 1 #
|
|
30
|
+
if month > 13: #
|
|
31
|
+
month = 1 #
|
|
32
|
+
year += 1 #
|
|
33
|
+
|
|
34
|
+
return {'year': year, 'month': month, 'day': day}
|
|
35
|
+
|
|
36
|
+
def add_months(ethiopian, months):
|
|
37
|
+
"""
|
|
38
|
+
Adds a specified number of months to an Ethiopian date.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
ethiopian (dict): The starting Ethiopian date {'year', 'month', 'day'}.
|
|
42
|
+
months (int): The number of months to add.
|
|
43
|
+
|
|
44
|
+
Returns:
|
|
45
|
+
dict: The resulting Ethiopian date.
|
|
46
|
+
"""
|
|
47
|
+
validate_ethiopian_date_object(ethiopian, 'add_months', 'ethiopian') #
|
|
48
|
+
validate_numeric_inputs('add_months', months=months) #
|
|
49
|
+
|
|
50
|
+
year, month, day = ethiopian['year'], ethiopian['month'], ethiopian['day']
|
|
51
|
+
|
|
52
|
+
total_months = month + months #
|
|
53
|
+
year += (total_months - 1) // 13 #
|
|
54
|
+
month = ((total_months - 1) % 13) + 1 #
|
|
55
|
+
|
|
56
|
+
# If the original day is greater than the number of days in the new month,
|
|
57
|
+
# cap it at the last day of the new month.
|
|
58
|
+
days_in_target_month = get_ethiopian_days_in_month(year, month) #
|
|
59
|
+
if day > days_in_target_month: #
|
|
60
|
+
day = days_in_target_month #
|
|
61
|
+
|
|
62
|
+
return {'year': year, 'month': month, 'day': day}
|
|
63
|
+
|
|
64
|
+
def add_years(ethiopian, years):
|
|
65
|
+
"""
|
|
66
|
+
Adds a specified number of years to an Ethiopian date.
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
ethiopian (dict): The starting Ethiopian date {'year', 'month', 'day'}.
|
|
70
|
+
years (int): The number of years to add.
|
|
71
|
+
|
|
72
|
+
Returns:
|
|
73
|
+
dict: The resulting Ethiopian date.
|
|
74
|
+
"""
|
|
75
|
+
validate_ethiopian_date_object(ethiopian, 'add_years', 'ethiopian') #
|
|
76
|
+
validate_numeric_inputs('add_years', years=years) #
|
|
77
|
+
|
|
78
|
+
year, month, day = ethiopian['year'], ethiopian['month'], ethiopian['day']
|
|
79
|
+
year += years #
|
|
80
|
+
|
|
81
|
+
# Handle the case where the original date was a leap day (Pagume 6),
|
|
82
|
+
# and the new date is in a non-leap year.
|
|
83
|
+
if month == 13 and day == 6 and not is_ethiopian_leap_year(year): #
|
|
84
|
+
day = 5 #
|
|
85
|
+
|
|
86
|
+
return {'year': year, 'month': month, 'day': day}
|
|
87
|
+
|
|
88
|
+
def diff_in_days(date_a, date_b):
|
|
89
|
+
"""
|
|
90
|
+
Calculates the difference in days between two Ethiopian dates.
|
|
91
|
+
|
|
92
|
+
Args:
|
|
93
|
+
date_a (dict): The first Ethiopian date.
|
|
94
|
+
date_b (dict): The second Ethiopian date.
|
|
95
|
+
|
|
96
|
+
Returns:
|
|
97
|
+
int: The difference in days.
|
|
98
|
+
"""
|
|
99
|
+
validate_ethiopian_date_object(date_a, 'diff_in_days', 'a') #
|
|
100
|
+
validate_ethiopian_date_object(date_b, 'diff_in_days', 'b') #
|
|
101
|
+
|
|
102
|
+
def total_days(eth_date): #
|
|
103
|
+
"""Helper to count days from a fixed epoch (year 1, month 1, day 1)."""
|
|
104
|
+
days = 0
|
|
105
|
+
# Add days from full years
|
|
106
|
+
for y in range(1, eth_date['year']): #
|
|
107
|
+
days += 366 if is_ethiopian_leap_year(y) else 365 #
|
|
108
|
+
# Add days from full months in the current year
|
|
109
|
+
for m in range(1, eth_date['month']): #
|
|
110
|
+
days += get_ethiopian_days_in_month(eth_date['year'], m)
|
|
111
|
+
# Add days in the current month
|
|
112
|
+
days += eth_date['day'] #
|
|
113
|
+
return days
|
|
114
|
+
|
|
115
|
+
return total_days(date_a) - total_days(date_b) #
|
|
116
|
+
|
|
117
|
+
def diff_in_months(date_a, date_b):
|
|
118
|
+
"""
|
|
119
|
+
Calculates the difference in months between two Ethiopian dates.
|
|
120
|
+
"""
|
|
121
|
+
validate_ethiopian_date_object(date_a, 'diff_in_months', 'a') #
|
|
122
|
+
validate_ethiopian_date_object(date_b, 'diff_in_months', 'b') #
|
|
123
|
+
|
|
124
|
+
total_months_a = date_a['year'] * 13 + (date_a['month'] - 1) #
|
|
125
|
+
total_months_b = date_b['year'] * 13 + (date_b['month'] - 1) #
|
|
126
|
+
|
|
127
|
+
diff = total_months_a - total_months_b #
|
|
128
|
+
|
|
129
|
+
# Adjust if the day of the later date hasn't been reached yet
|
|
130
|
+
if date_a['day'] < date_b['day']: #
|
|
131
|
+
diff -= 1 #
|
|
132
|
+
|
|
133
|
+
return diff
|
|
134
|
+
|
|
135
|
+
def diff_in_years(date_a, date_b):
|
|
136
|
+
"""
|
|
137
|
+
Calculates the difference in years between two Ethiopian dates.
|
|
138
|
+
"""
|
|
139
|
+
validate_ethiopian_date_object(date_a, 'diff_in_years', 'a') #
|
|
140
|
+
validate_ethiopian_date_object(date_b, 'diff_in_years', 'b') #
|
|
141
|
+
|
|
142
|
+
diff = date_a['year'] - date_b['year']
|
|
143
|
+
|
|
144
|
+
# If the month/day of 'a' is earlier in the year than 'b',
|
|
145
|
+
# a full year has not yet passed.
|
|
146
|
+
if date_a['month'] < date_b['month'] or \
|
|
147
|
+
(date_a['month'] == date_b['month'] and date_a['day'] < date_b['day']): #
|
|
148
|
+
diff -= 1 #
|
|
149
|
+
|
|
150
|
+
return diff
|