Skip to content

Commit

Permalink
Calculate Easter date automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
luk3yx committed Mar 17, 2024
1 parent 79417cb commit a31ef98
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ The license for the sounds are listed in the sounds folder.

The easter stuff is CC0.

The date calculation algorithm in init.lua is [copied from dateutil](https://github.com/dateutil/dateutil/blob/1ae807774053c071acc9e7d3d27778fba0a7773e/src/dateutil/easter.py) and is therefore under the [Apache-2.0 license](https://github.com/dateutil/dateutil/blob/1ae807774053c071acc9e7d3d27778fba0a7773e/LICENSE).

## Christmas

The christmas stuff was written by Billy-S, w/ no given license.
Expand Down
22 changes: 21 additions & 1 deletion init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,29 @@ local function or_(...)
end
end

-- Easter calculation, copied from dateutil (see LICENSE)
local floor = math.floor
local function get_month_and_day(p)
return {month=3 + floor((p + 26)/30), day=1 + (p + 27 + floor((p + 6)/40)) % 31}
end

local function is_easter(date)
local y = date.year
local g = y % 19
local c = floor(y / 100)
local h = (c - floor(c/4) - floor((8*c + 13)/25) + 19*g + 15) % 30
local i = h - (floor(h/28))*(1 - (floor(h/28))*floor(29/(h + 1))*floor((21 - g)/11))
local j = (y + floor(y/4) + i + 2 - c + floor(c/4)) % 7
local p = i - j

local start = get_month_and_day(p - 4)
local stop = get_month_and_day(p + 1)
return date_lte(start, date) and date_lte(date, stop)
end

holidays.schedule = {
christmas = date_range_predicate({month=12, day=1}, {month=12, day=26}), -- 2019 date
easter = date_range_predicate({month=3, day=27}, {month=4, day=1}), -- 2024 date
easter = is_easter,
fireworks = or_(
date_range_predicate({month=7, day=2}, {month=7, day=5}), -- july 4th
date_range_predicate({month=12, day=27}, {month=1, day=10}) -- new years
Expand Down

0 comments on commit a31ef98

Please sign in to comment.