-
-
Notifications
You must be signed in to change notification settings - Fork 539
Create gambia.py #2447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Create gambia.py #2447
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
from datetime import date | ||
import holidays | ||
from hijri_converter import Gregorian | ||
|
||
def get_gambia_holidays(year): | ||
gambia_holidays = {} | ||
try: | ||
gm_holidays = holidays.GM(years=year) | ||
gambia_holidays.update(gm_holidays) | ||
except KeyError: | ||
gambia_holidays.update(_get_manual_gambia_holidays(year)) | ||
except Exception as e: | ||
print(f"Error retrieving holidays for {year}: {e}") | ||
gambia_holidays.update(_get_manual_gambia_holidays(year)) | ||
return gambia_holidays | ||
yashwanth2307 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def _get_manual_gambia_holidays(year): | ||
manual_holidays = {} | ||
manual_holidays[date(year, 1, 1)] = "New Year's Day" | ||
manual_holidays[date(year, 2, 18)] = "Independence Day" | ||
manual_holidays[date(year, 5, 1)] = "Labour Day" | ||
manual_holidays[date(year, 5, 25)] = "Africa Day" | ||
manual_holidays[date(year, 7, 22)] = "Revolution Day" | ||
manual_holidays[date(year, 8, 15)] = "Assumption of Mary" | ||
manual_holidays[date(year, 12, 25)] = "Christmas Day" | ||
|
||
# Calculate approximate Christian movable holidays (simplified) | ||
easter_sunday = _calculate_easter(year) | ||
if easter_sunday: | ||
manual_holidays[easter_sunday - timedelta(days=2)] = "Good Friday (Approximate)" | ||
manual_holidays[easter_sunday + timedelta(days=1)] = "Easter Monday (Approximate)" | ||
|
||
# Calculate approximate Islamic holidays (using hijri-converter) | ||
try: | ||
if year >= 2000: | ||
# Approximate dates based on common patterns and estimations | ||
# Note: Actual dates depend on moon sighting. | ||
hijri_year_start = Gregorian(year, 1, 1).to_hijri().year | ||
# Eid al-Fitr (end of Ramadan) - roughly 9th/10th month | ||
gregorian_eid_fitr = Gregorian(hijri_year_start + (year - 2000), 10, 1).to_gregorian() | ||
manual_holidays[gregorian_eid_fitr] = "Eid al-Fitr (Approximate)" | ||
|
||
# Eid al-Adha (Feast of Sacrifice) - roughly 12th month, 10th day | ||
gregorian_eid_adha = Gregorian(hijri_year_start + (year - 2000), 12, 10).to_gregorian() | ||
manual_holidays[gregorian_eid_adha] = "Eid al-Adha (Approximate)" | ||
|
||
# Mawlid (Prophet's Birthday) - roughly 3rd month, 12th day | ||
gregorian_mawlid = Gregorian(hijri_year_start + (year - 2000), 3, 12).to_gregorian() | ||
manual_holidays[gregorian_mawlid] = "The Prophet's Birthday (Approximate)" | ||
except Exception as e: | ||
print(f"Error calculating Islamic holidays for {year}: {e}") | ||
|
||
yashwanth2307 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return manual_holidays | ||
|
||
def _calculate_easter(year): | ||
"""Simplified Easter calculation (Gregorian calendar).""" | ||
a = year % 19 | ||
b = year // 100 | ||
c = year % 100 | ||
d = (19 * a + b - b // 4 - (b - (b + 8) // 25 + 1) // 3 + 15) % 30 | ||
e = (32 + 2 * (b % 4) + 2 * (c // 4) - d - (c % 4)) % 7 | ||
month = (d + e + 114) // 31 | ||
day = ((d + e + 114) % 31) + 1 | ||
try: | ||
return date(year, month, day) | ||
except ValueError: | ||
return None | ||
|
||
if __name__ == "__main__": | ||
from datetime import timedelta | ||
|
||
start_year = 2025 | ||
end_year = start_year + 30 | ||
all_gambia_holidays = {} | ||
|
||
for year in range(start_year, end_year): | ||
gambia_holidays = get_gambia_holidays(year) | ||
if gambia_holidays: | ||
print(f"\nPublic Holidays in The Gambia for {year}:") | ||
for date_obj, name in sorted(gambia_holidays.items()): | ||
print(f"{date_obj}: {name}") | ||
all_gambia_holidays.update(gambia_holidays) | ||
else: | ||
print(f"\nCould not retrieve specific holiday data for {year}.") | ||
|
||
print("\n--- Important Notes ---") | ||
print("1. The 'holidays' library may not fully support Gambia for all years.") | ||
print("2. Dates for Islamic holidays are subject to moon sighting and can vary by a day or two.") | ||
print("3. Dates for Christian movable holidays (Good Friday, Easter Monday) are approximate calculations.") | ||
print("4. For precise dates, especially for religious holidays, consult official Gambian government announcements and reliable religious calendars for each specific year.") | ||
yashwanth2307 marked this conversation as resolved.
Show resolved
Hide resolved
yashwanth2307 marked this conversation as resolved.
Show resolved
Hide resolved
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
8000 Uh oh!
There was an error while loading. Please reload this page.