[Remind-Fans] Determining Ramadan & Eid?

Ruthard Baudach ruthard.baudach at web.de
Mon Apr 24 14:56:13 EDT 2023


So I couldn't control myself during holidays...

Using https://github.com/espinielli/pycalcal

(which needs mpmath. pycalcal is officially not python3, but works
just fine. if no python2.7 is installed, it has to be installed from
git, and mpmath installed on it's own)

I wrote this script, which calculates the Gregorian date of the first
day(s) of Ramadan(s) occuring in the next Gregorian year and appending
a REM-line to a reminder file.

Actual Ramadan might be ± 2 days off according to local customs.

-----------------%<----------------
#!/usr/bin/env python

import datetime
import os
import pycalcal as PC

# path to reminder file -- use your own, of course.
path_to_holiday_reminders = os.path.join(
        os.environ['HOME'],
        '.remind',
        'holidays-test.rem')

# template for reminder line
reminder_text = 'REM {}-{}-{} MSG Ramadan (probably)'

#next gregorian year
gregorian_next_year = datetime.datetime.today().year + 1

# next gregorian new year as fixed date
next_gregorian_new_year_as_fixed = PC.fixed_from_gregorian(PC.gregorian_date(gregorian_next_year, 1, 1))

# islamic year of next gregorian new year
islamic_year = PC.standard_year(PC.islamic_from_fixed(next_gregorian_new_year_as_fixed))

# Ramadan 1st of islamic year occuring during the next gregorian new year as fixed date
first_of_ramadan_as_fixed = PC.fixed_from_islamic(PC.islamic_date(islamic_year, 9, 1))

# make sure Ramadan is not in the past, may occur if we run during
# Shawwal - Dhul Hijjah
if first_of_ramadan_as_fixed < next_gregorian_new_year_as_fixed:
    islamic_year += 1
    # ramadan as fixed
    first_of_ramadan_as_fixed = PC.fixed_from_islamic(PC.islamic_date(islamic_year, 9, 1))

# Ramadan the 1st as gregorian date
first_of_ramadan_as_gregorian = PC.gregorian_from_fixed(first_of_ramadan_as_fixed)

# print reminder 
with open(path_to_holiday_reminders,'a') as f:
    print(reminder_text.format(*first_of_ramadan_as_gregorian),file=f)

# take care of possible second ramadan.
# how many days is the islamic year (354 days) shorter than the
# current gregorian year (365/366 days)?
if PC.is_gregorian_leap_year(gregorian_next_year):
    islamic_gregorian_delta = 12
else:
    islamic_gregorian_delta = 11

# Ramadan 1st as day of gregorian year
first_of_ramadan_as_day_of_gregorian_year = first_of_ramadan_as_fixed - next_gregorian_new_year_as_fixed

if first_of_ramadan_as_day_of_gregorian_year <= islamic_gregorian_delta:
    islamic_year += 1
    # second Ramadan 1st as fixed date
    first_of_ramadan_as_fixed = PC.fixed_from_islamic(PC.islamic_date(islamic_year, 9, 1))

    # Ramadan the 1st as gregorian date
    first_of_ramadan_as_gregorian = PC.gregorian_from_fixed(first_of_ramadan_as_fixed)

    # print reminder 
    with open(path_to_holiday_reminders,'a') as f:
        print(reminder_text.format(*first_of_ramadan_as_gregorian),file=f)

----------------->%----------------


Quoting Tim Chase via Remind-fans (2023-03-22 18:47:50)
> Howdy,
> 
> I wanted to put the start of Ramadan and end of Ramadan (Eid) on
> my calendar but it's based on a lunar calendar so I'm not quite
> sure how to create such events.  My understanding is that the Hebrew
> calendar (for which there are functions in Remind) is also lunar-based,
> but as best I can tell, they don't overlap:
> 
> https://stevemorse.org/jcal/mrules.htm
> 
> Any recommendations on determining these events?
> 
> Thanks,
> 
> -Tim
> 
> 
> 
> 
> 
> 
> _______________________________________________
> Remind-fans mailing list
> Remind-fans at lists.skoll.ca
> https://dianne.skoll.ca/mailman/listinfo/remind-fans
> Remind is at https://dianne.skoll.ca/projects/remind/



More information about the Remind-fans mailing list