4 ms·
I think this just speaks to a design wart in the seemingly simple crontab specification. I'm personally more of a fan of iCal-style (RFC5545) recurrence specifi
by kccqzy 4y ago
I think this just speaks to a design wart in the seemingly simple crontab specification. I'm personally more of a fan of iCal-style (RFC5545) recurrence specification. Just check out the examples in https://www.rfc-editor.org/rfc/rfc5545#section-3.8.5.3 https://www.rfc-editor.org/rfc/rfc5545#section-3.8.5.3
Here are some thing that's possible:
Weekly on Tuesday and Thursday for five weeks
Every other week on Monday, Wednesday, and Friday until December 24, 1997, starting on Monday, September 1, 1997
Every other month on the first and last Sunday of the month for 10 occurrences
Every 18 months on the 10th thru 15th of the month
(Almost all of those are well supported by the UI on Apple Calendar and Google Calendar.)
I only wish it could incorporate astronomical phenomena such as phases of the moon into account. Wouldn't it be great if it can express concepts like "the first Sunday after the full moon that occurs on or after the spring equinox" (no I'm not making this example up)?
- dogline 4y agoI guess you can just say "Easter 2023"
- macintux 4y agoOrthodox or Catholic?
- gsich 4y agogauß doesn't care, the changes are minimal.
- kccqzy 4y agoThe 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)
- playingalong 4y agoNo one said it was 2023
- xani_ 4y agoAt that point you might as well put a code interpreter in your scheduler that just gets current date and returns next data of event, because whole code to cover that would take more code than cron itself.
- layer8 4y agoThere is a trend towards turing-complete configuration languages, so why not. Of course there might be a race condition if the computation takes longer than the remaining time to the computed date.
- ranit 4y agoThis is so easy, just interpret a few hundred words :) https://en.m.wikipedia.org/wiki/Date_of_Easter https://en.m.wikipedia.org/wiki/Date_of_Easter … and you would still be wrong, depending in which country it gets calculated.
- guipsp 4y agoThe things that are possible that are specified in the the parent is not how you actually write them fyi
- blowski 4y agoPhases of the moon are still important if you live near a body of water with strong tides. They also used to be important as a source of light.
- gw99 4y agoI wrote an RFC5545 parser and event generator once. No thanks.
- zokier 4y ago> I only wish it could incorporate astronomical phenomena such as phases of the moon into account You probably could hack something up around rfc 7529 (non-gregorian recurrence)