3 ms·
The idea is not to hard code the computation of specific holidays, but to make the specification flexible enough.
by kccqzy 4y ago
The idea is not to hard code the computation of specific holidays, but to make the specification flexible enough.
- anvandare 4y agoOnce dates get too complex it is easier to just have an external script figure out whether today is the day and have it run every day: 0 9 * * * anvandare is-today-the-day.py && celebrate.sh With is-today-the-day.py being: #!/usr/bin/env python3 import sys from dateutil.easter import easter from datetime import datetime as dt today = dt.today().date() (easter(2023) - today).days == 0 and sys.exit(0) or sys.exit(1) Or, if we didn't have the easter function already (just adding this because it was fun to work it out): #!/usr/bin/env python3 import sys, ephem as e, datetime as dt setup = '2022/09/25' date = (e.next_full_moon(e.next_equinox(setup))).datetime() easter2023 = (date + dt.timedelta(7 - date.isoweekday())).date() today = dt.datetime.today().date() (easter2023 - today).days == 0 and sys.exit(0) or sys.exit(1)