← Back to context

Comment by sublinear

7 hours ago

I had something come up recently that I think sounds similar. That project needs several time-sensitive jobs. When any one of them runs, the first thing it does is check a holidays.json file.

It parses the file using jq and compares its entries with the current time according to GNU date. At the root is the names of the jobs. Each job has its own list of holidays. Each of these holiday items in the job's respective list has keys for the display name of the holiday, the formatted date to compare to, and in a few cases the ISO day-of-week and a string containing a modulo arithmetic function (e.g. don't run the friday before Christmas, etc.).

Sorry, yes that means I call eval on that string and yes that means some of these are repeated in the same file under the arrays for the other jobs. Also, such lists will have to be maintained and the exact observed dates cannot always be known ahead of time beyond about a year since people can change their minds for various reasons (think bank holidays). Depending on your use case you may also want to define a start time and end time for a window of when this should or shouldn't run (i.e. business hours).

I don't know if that helps. I know it's hacky, but I don't think there's a nice way to handle things like "second monday after 4th of july, but if the 4th also happens to be monday then it should instead be the second tuesday". God help you if you also need to handle each holiday being observed in different timezones. At least at the end of the day none of this would be much code, just very terse code dense with meaning.