Created
May 14, 2023 02:28
-
-
Save abe-101/2a85ff3d468f68149611e3d51522e0c2 to your computer and use it in GitHub Desktop.
This script generates a dictionary of Hebrew dates for the next three years and their corresponding Gregorian dates
This file contains 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
from datetime import date, timedelta | |
from pyluach import dates | |
def create_hebrew_to_english_dict(): | |
hebrew_to_english_dict = {} | |
first_gregorian_date = date.today() # two years ago | |
first_hebrew_date = dates.HebrewDate.from_pydate(first_gregorian_date) | |
for i in range(365 * 3): # three years | |
hebrew_date = dates.HebrewDate.from_pydate(first_gregorian_date + timedelta(days=i)) | |
hebrew_date_str = f"{hebrew_date.month}-{hebrew_date.day}" | |
english_date = hebrew_date.to_greg().strftime("%Y-%m-%d") | |
if hebrew_date_str not in hebrew_to_english_dict: | |
hebrew_to_english_dict[hebrew_date_str] = [english_date] | |
else: | |
hebrew_to_english_dict[hebrew_date_str].append(english_date) | |
return hebrew_to_english_dict | |
hebrew_to_english_dict = create_hebrew_to_english_dict() | |
# You can then access the English dates corresponding to a given Hebrew date like this: | |
hebrew_date = '4-23' | |
english_dates = hebrew_to_english_dict[hebrew_date] | |
print(english_dates) # outputs ['2023-07-12', '2024-07-29', '2025-07-19'] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment