kenat 1.0.0__tar.gz
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-1.0.0/LICENSE +21 -0
- kenat-1.0.0/PKG-INFO +206 -0
- kenat-1.0.0/README.md +182 -0
- kenat-1.0.0/kenat/__init__.py +24 -0
- kenat-1.0.0/kenat/bahire_hasab.py +133 -0
- kenat-1.0.0/kenat/constants.py +185 -0
- kenat-1.0.0/kenat/conversions.py +148 -0
- kenat-1.0.0/kenat/day_arithmetic.py +150 -0
- kenat-1.0.0/kenat/exceptions.py +63 -0
- kenat-1.0.0/kenat/formatting.py +67 -0
- kenat-1.0.0/kenat/geez_converter.py +112 -0
- kenat-1.0.0/kenat/holidays.py +171 -0
- kenat-1.0.0/kenat/kenat.py +281 -0
- kenat-1.0.0/kenat/month_grid.py +106 -0
- kenat-1.0.0/kenat/time.py +196 -0
- kenat-1.0.0/kenat/utils.py +104 -0
- kenat-1.0.0/kenat.egg-info/PKG-INFO +206 -0
- kenat-1.0.0/kenat.egg-info/SOURCES.txt +31 -0
- kenat-1.0.0/kenat.egg-info/dependency_links.txt +1 -0
- kenat-1.0.0/kenat.egg-info/requires.txt +4 -0
- kenat-1.0.0/kenat.egg-info/top_level.txt +1 -0
- kenat-1.0.0/pyproject.toml +41 -0
- kenat-1.0.0/setup.cfg +4 -0
- kenat-1.0.0/tests/test_bahire_hasab.py +89 -0
- kenat-1.0.0/tests/test_calendar_generation.py +43 -0
- kenat-1.0.0/tests/test_conversions.py +68 -0
- kenat-1.0.0/tests/test_day_arithmetic.py +145 -0
- kenat-1.0.0/tests/test_geez_converter.py +86 -0
- kenat-1.0.0/tests/test_holidays.py +105 -0
- kenat-1.0.0/tests/test_kenat.py +100 -0
- kenat-1.0.0/tests/test_month_grid.py +105 -0
- kenat-1.0.0/tests/test_time.py +102 -0
- kenat-1.0.0/tests/test_utils.py +67 -0
kenat-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Melaku Demeke
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
kenat-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kenat
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A comprehensive Python library for the Ethiopian calendar, handling conversions, holidays (Bahire Hasab), and date arithmetic.
|
|
5
|
+
Author-email: Melaku Demeke <melaku.demeke789@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://www.kenat.systems/
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/MelakuDemeke/kenat/issues
|
|
9
|
+
Keywords: ethiopian,calendar,kenat,ethiopia,bahire hasab,date conversion,amharic
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
16
|
+
Classifier: Topic :: Utilities
|
|
17
|
+
Requires-Python: >=3.8
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Provides-Extra: test
|
|
21
|
+
Requires-Dist: pytest; extra == "test"
|
|
22
|
+
Requires-Dist: pytest-mock; extra == "test"
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# Kenat_PY ยท แแแต ๐ช๐น
|
|
26
|
+
|
|
27
|
+

|
|
28
|
+
|
|
29
|
+

|
|
30
|
+

|
|
31
|
+

|
|
32
|
+

|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
**A complete Ethiopian Calendar & Bahire Hasab toolkit for Python**
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## ๐ Overview
|
|
40
|
+
|
|
41
|
+
**Kenat** (Amharic: แแแต) is a powerful and authentic Ethiopian calendar library for Python. It offers full support for date conversion, holiday computation (including Bahire Hasab), localized formatting, Geez numerals, and more โ all without external dependencies.
|
|
42
|
+
|
|
43
|
+
> ๐ Ported from the original [kenat JS library](https://github.com/melaku/kenat).
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## โจ Features
|
|
48
|
+
|
|
49
|
+
* ๐ **Bidirectional Conversion**: Ethiopian โ Gregorian calendars
|
|
50
|
+
* ๐
**Full Holiday System**: Christian, Muslim, cultural, and public holidays
|
|
51
|
+
* โช **Bahire Hasab**: Accurate movable feast calculations (e.g. Fasika, Tsome Nebiyat)
|
|
52
|
+
* ๐ท๏ธ **Holiday Filtering**: Filter holidays by type (`public`, `christian`, `muslim`, etc.)
|
|
53
|
+
* ๐ **Date Arithmetic**: Add/subtract days, months, years (13-month calendar support)
|
|
54
|
+
* ๐ **Localized Formatting**: Amharic and English support
|
|
55
|
+
* ๐ข **Geez Numerals**: Convert integers to แแแ numeral strings
|
|
56
|
+
* โฐ **Ethiopian Time Support**: 12-hour Ethiopian โ 24-hour Gregorian
|
|
57
|
+
* ๐๏ธ **Calendar Grids**: Monthly/yearly calendar generation
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## ๐ Installation
|
|
62
|
+
|
|
63
|
+
Install the library from source:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pip install .
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
For development/testing:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install -e ".[test]"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## ๐ข Quick Start
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from kenat import Kenat
|
|
81
|
+
|
|
82
|
+
today = Kenat.now()
|
|
83
|
+
|
|
84
|
+
print(today.get_ethiopian())
|
|
85
|
+
# โ {'year': 2017, 'month': 9, 'day': 26}
|
|
86
|
+
|
|
87
|
+
print(today.format({'lang': 'english', 'show_weekday': True}))
|
|
88
|
+
# โ "Tuesday, Ginbot 26 2017"
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## โช Bahire Hasab & Holiday System
|
|
94
|
+
|
|
95
|
+
### Get All Holidays in a Year
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
from kenat import get_holidays_for_year
|
|
99
|
+
|
|
100
|
+
holidays = get_holidays_for_year(2017)
|
|
101
|
+
|
|
102
|
+
# Example: Find Fasika (Easter)
|
|
103
|
+
fasika = next(h for h in holidays if h['key'] == 'fasika')
|
|
104
|
+
print(fasika['ethiopian']) # โ {'year': 2017, 'month': 8, 'day': 21}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Filter Holidays by Type
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
from kenat import get_holidays_for_year, HolidayTags
|
|
111
|
+
|
|
112
|
+
# Public only
|
|
113
|
+
get_holidays_for_year(2017, filter_by=HolidayTags.PUBLIC)
|
|
114
|
+
|
|
115
|
+
# Christian and Muslim holidays
|
|
116
|
+
get_holidays_for_year(2017, filter_by=[HolidayTags.CHRISTIAN, HolidayTags.MUSLIM])
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Check if a Date is a Holiday
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
from kenat import Kenat
|
|
123
|
+
|
|
124
|
+
meskel = Kenat("2017/1/17")
|
|
125
|
+
print(meskel.is_holiday()) # โ [Holiday object]
|
|
126
|
+
|
|
127
|
+
non_holiday = Kenat("2017/1/18")
|
|
128
|
+
print(non_holiday.is_holiday()) # โ []
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Access Bahire Hasab Calculations
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
from kenat import Kenat
|
|
135
|
+
|
|
136
|
+
bh = Kenat("2017/1/1").get_bahire_hasab()
|
|
137
|
+
|
|
138
|
+
print(bh['evangelist']) # โ {'name': 'แแดแแต', 'remainder': 1}
|
|
139
|
+
print(bh['movableFeasts']['fasika']['ethiopian'])
|
|
140
|
+
# โ {'year': 2017, 'month': 8, 'day': 21}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## โ More API Examples
|
|
146
|
+
|
|
147
|
+
### Date Arithmetic
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
from kenat import Kenat
|
|
151
|
+
|
|
152
|
+
date = Kenat("2017/2/10")
|
|
153
|
+
print(date.add(days=10)) # โ Add days
|
|
154
|
+
print(date.add(months=-1)) # โ Subtract a month
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Date Difference
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
from kenat import Kenat
|
|
161
|
+
|
|
162
|
+
a = Kenat("2015/5/15")
|
|
163
|
+
b = Kenat("2012/5/15")
|
|
164
|
+
|
|
165
|
+
print((a - b).days) # โ 1095 days
|
|
166
|
+
print(a.diff_in_days(b)) # โ 1095
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Geez Numerals
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
from kenat import to_geez
|
|
173
|
+
|
|
174
|
+
print(to_geez(2017)) # โ แณแปแฒแฏ
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## ๐งฑ Contributing
|
|
180
|
+
|
|
181
|
+
1. Fork & clone the repo
|
|
182
|
+
2. Create a new branch: `git checkout -b feature/your-feature`
|
|
183
|
+
3. Make your changes, add tests in `/tests/`
|
|
184
|
+
4. Run `pytest` to ensure everything passes
|
|
185
|
+
5. Submit a pull request ๐
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## ๐จโ๐ป Author
|
|
190
|
+
|
|
191
|
+
**Melaku Demeke**
|
|
192
|
+
GitHub: [@melakud](https://github.com/melakud)
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## ๐ License
|
|
197
|
+
|
|
198
|
+
**MIT License** โ see [LICENSE](./LICENSE) for details.
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
Let me know if you want to:
|
|
203
|
+
|
|
204
|
+
* add badges (PyPI, license, tests)
|
|
205
|
+
* include an animated GIF demo (e.g. calendar grid or console output)
|
|
206
|
+
* or generate this as a `README.md` file automatically.
|
kenat-1.0.0/README.md
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# Kenat_PY ยท แแแต ๐ช๐น
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
**A complete Ethiopian Calendar & Bahire Hasab toolkit for Python**
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## ๐ Overview
|
|
16
|
+
|
|
17
|
+
**Kenat** (Amharic: แแแต) is a powerful and authentic Ethiopian calendar library for Python. It offers full support for date conversion, holiday computation (including Bahire Hasab), localized formatting, Geez numerals, and more โ all without external dependencies.
|
|
18
|
+
|
|
19
|
+
> ๐ Ported from the original [kenat JS library](https://github.com/melaku/kenat).
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## โจ Features
|
|
24
|
+
|
|
25
|
+
* ๐ **Bidirectional Conversion**: Ethiopian โ Gregorian calendars
|
|
26
|
+
* ๐
**Full Holiday System**: Christian, Muslim, cultural, and public holidays
|
|
27
|
+
* โช **Bahire Hasab**: Accurate movable feast calculations (e.g. Fasika, Tsome Nebiyat)
|
|
28
|
+
* ๐ท๏ธ **Holiday Filtering**: Filter holidays by type (`public`, `christian`, `muslim`, etc.)
|
|
29
|
+
* ๐ **Date Arithmetic**: Add/subtract days, months, years (13-month calendar support)
|
|
30
|
+
* ๐ **Localized Formatting**: Amharic and English support
|
|
31
|
+
* ๐ข **Geez Numerals**: Convert integers to แแแ numeral strings
|
|
32
|
+
* โฐ **Ethiopian Time Support**: 12-hour Ethiopian โ 24-hour Gregorian
|
|
33
|
+
* ๐๏ธ **Calendar Grids**: Monthly/yearly calendar generation
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## ๐ Installation
|
|
38
|
+
|
|
39
|
+
Install the library from source:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install .
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
For development/testing:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install -e ".[test]"
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## ๐ข Quick Start
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from kenat import Kenat
|
|
57
|
+
|
|
58
|
+
today = Kenat.now()
|
|
59
|
+
|
|
60
|
+
print(today.get_ethiopian())
|
|
61
|
+
# โ {'year': 2017, 'month': 9, 'day': 26}
|
|
62
|
+
|
|
63
|
+
print(today.format({'lang': 'english', 'show_weekday': True}))
|
|
64
|
+
# โ "Tuesday, Ginbot 26 2017"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## โช Bahire Hasab & Holiday System
|
|
70
|
+
|
|
71
|
+
### Get All Holidays in a Year
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from kenat import get_holidays_for_year
|
|
75
|
+
|
|
76
|
+
holidays = get_holidays_for_year(2017)
|
|
77
|
+
|
|
78
|
+
# Example: Find Fasika (Easter)
|
|
79
|
+
fasika = next(h for h in holidays if h['key'] == 'fasika')
|
|
80
|
+
print(fasika['ethiopian']) # โ {'year': 2017, 'month': 8, 'day': 21}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Filter Holidays by Type
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from kenat import get_holidays_for_year, HolidayTags
|
|
87
|
+
|
|
88
|
+
# Public only
|
|
89
|
+
get_holidays_for_year(2017, filter_by=HolidayTags.PUBLIC)
|
|
90
|
+
|
|
91
|
+
# Christian and Muslim holidays
|
|
92
|
+
get_holidays_for_year(2017, filter_by=[HolidayTags.CHRISTIAN, HolidayTags.MUSLIM])
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Check if a Date is a Holiday
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
from kenat import Kenat
|
|
99
|
+
|
|
100
|
+
meskel = Kenat("2017/1/17")
|
|
101
|
+
print(meskel.is_holiday()) # โ [Holiday object]
|
|
102
|
+
|
|
103
|
+
non_holiday = Kenat("2017/1/18")
|
|
104
|
+
print(non_holiday.is_holiday()) # โ []
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Access Bahire Hasab Calculations
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
from kenat import Kenat
|
|
111
|
+
|
|
112
|
+
bh = Kenat("2017/1/1").get_bahire_hasab()
|
|
113
|
+
|
|
114
|
+
print(bh['evangelist']) # โ {'name': 'แแดแแต', 'remainder': 1}
|
|
115
|
+
print(bh['movableFeasts']['fasika']['ethiopian'])
|
|
116
|
+
# โ {'year': 2017, 'month': 8, 'day': 21}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## โ More API Examples
|
|
122
|
+
|
|
123
|
+
### Date Arithmetic
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
from kenat import Kenat
|
|
127
|
+
|
|
128
|
+
date = Kenat("2017/2/10")
|
|
129
|
+
print(date.add(days=10)) # โ Add days
|
|
130
|
+
print(date.add(months=-1)) # โ Subtract a month
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Date Difference
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
from kenat import Kenat
|
|
137
|
+
|
|
138
|
+
a = Kenat("2015/5/15")
|
|
139
|
+
b = Kenat("2012/5/15")
|
|
140
|
+
|
|
141
|
+
print((a - b).days) # โ 1095 days
|
|
142
|
+
print(a.diff_in_days(b)) # โ 1095
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Geez Numerals
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
from kenat import to_geez
|
|
149
|
+
|
|
150
|
+
print(to_geez(2017)) # โ แณแปแฒแฏ
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## ๐งฑ Contributing
|
|
156
|
+
|
|
157
|
+
1. Fork & clone the repo
|
|
158
|
+
2. Create a new branch: `git checkout -b feature/your-feature`
|
|
159
|
+
3. Make your changes, add tests in `/tests/`
|
|
160
|
+
4. Run `pytest` to ensure everything passes
|
|
161
|
+
5. Submit a pull request ๐
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## ๐จโ๐ป Author
|
|
166
|
+
|
|
167
|
+
**Melaku Demeke**
|
|
168
|
+
GitHub: [@melakud](https://github.com/melakud)
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## ๐ License
|
|
173
|
+
|
|
174
|
+
**MIT License** โ see [LICENSE](./LICENSE) for details.
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
Let me know if you want to:
|
|
179
|
+
|
|
180
|
+
* add badges (PyPI, license, tests)
|
|
181
|
+
* include an animated GIF demo (e.g. calendar grid or console output)
|
|
182
|
+
* or generate this as a `README.md` file automatically.
|
|
@@ -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
|
+
]
|
|
@@ -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)
|