itsallcode / holiday-calculator Goto Github PK
View Code? Open in Web Editor NEWA Java library for calculating dates of public holidays
License: GNU General Public License v3.0
A Java library for calculating dates of public holidays
License: GNU General Public License v3.0
/**
* (defun easter-eastern (year)
* (let* ((x (% (+ (* (% year 19) 19) 15) 30))
* (day (- (+ x 10)
* (% (+ (/ (* year 5) 4) x) 7))))
* (if (< day 31)
* (list 4 day year)
* (list 5 (- day 30) year))))
* source https://www.emacswiki.org/emacs/ukrainian-holidays.el
*/
public static LocalDate orthodoxEaster(int year) {
int x = ((year % 19) * 19 + 15) % 30;
int day = x + 10 - (((5 * year) / 4 + x) % 7);
if (day < 31) {
return LocalDate.of(year, 4, day);
} else {
return LocalDate.of(year, 5, day - 30);
}
}
Required for scandinavian countries.
In order to support holidays like in
Examples for rationale
(unless sv-hide-some-holidays (holiday-fixed 1 28 "Konungens namnsdag"))
Example for syntax
holiday-fixed 1 2 Новогодние каникулы # New Year holidays
Example
(holiday-sexp
'(let ((day (calendar-nth-named-day 1 0 2 year 2)))
(if (equal day (caar (holiday-easter-etc -49)))
(caar (holiday-easter-etc -56))
day))
"Kynttilänpäivä")
computes
holiday float 1 SUN after 2 2 Kynttilänpäivä
potential syntax
holiday either float 1 Sun after FEB 2 of if equal to easter -49 then easter -56 Kynttilänpäivä
(holiday-sexp
'(let ((day (calendar-nth-named-day 1 0 3 year 22)))
(if (or (equal day (caar (holiday-easter-etc 0)))
(equal day (caar (holiday-easter-etc -7))))
(caar (holiday-easter-etc -14))
day))
"Marian ilmestyspäivä")
computes
holiday float 1 Sun after MAR 22 Marian ilmestyspäivä
potential syntax
holiday either float 1 Sun after MAR 22 of if equal to easter 0,easter -7 then easter -14 Kynttilänpäivä
e.g. UK and Netherlands have cases in which
Dutch holidays contains the following code meaning: if April 27 is a Sunday then April 26, otherwise April 27:
(holiday-sexp
'(if (zerop (calendar-day-of-week (list 4 27 year)))
(list 4 26 year)
(list 4 27 year))
"Koningsdag")
Uk-holidays describe New Year bank holiday, being on January 1st except if this is SAT or SUN, then next Monday:
(defun holiday-new-year-bank-holiday ()
(let ((m displayed-month)
(y displayed-year))
(calendar-increment-month m y 1)
(when (<= m 3)
(let ((d (calendar-day-of-week (list 1 1 y))))
(cond ((= d 6) `(((1 3 ,y) "New Year's Day Bank Holiday")))
((= d 0) `(((1 2 ,y) "New Year's Day Bank Holiday"))))))))
(defun holiday-christmas-bank-holidays ()
(let ((m displayed-month)
(y displayed-year))
(calendar-increment-month m y -1)
(when (>= m 10)
(let ((d (calendar-day-of-week (list 12 25 y))))
(cond ((= d 5) `(((12 28 ,y) "Boxing Day Bank Holiday")))
((= d 6) `(((12 27 ,y) "Boxing Day Bank Holiday")
((12 28 ,y) "Christmas Day Bank Holiday")))
((= d 0) `(((12 27 ,y) "Christmas Day Bank Holiday"))))))))
In the following table X and B are Christmas and Boxing holidays defined anyway with a fixed date.
X2 and B2 are potential additional Christmas and Boxing holidays depending on the day of week of Dec 25th.
Case | 25 | 26 | 27 | 28 | Description |
---|---|---|---|---|---|
FRI | SAT | SUN | MON | ||
1 | X | B | - | B2 | if DEC 25 is a FRI then 12 28 Boxing Day Bank Holiday |
SAT | SUN | MON | TUE | ||
2 | X | B | B2 | X2 | if DEC 25 is a SAT then 12 27 Boxing Day Bank Holiday and 12 28 Christmas Day Bank Holiday |
SUN | MON | TUE | WED | ||
3 | X | B | X2 | if DEC 25 is a SUN then 12 27 Christmas Day Bank Holiday |
holiday either 4 27 or -1 if SUN Koningsdag
holiday if 4 27 is SUN then 4 26 Koningsdag
holiday except SUN 4 27 else 4 26 Koningsdag
holiday if-not SUN then 4 27 else 1 day before Koningsdag
holiday either fixed 4 27 or if SUN then fixed 4 26 Koningsdag
# leads to two holidays on Jan 1st in other cases
holiday either fixed JAN 1 or if SAT,SUN then float 1 MON after JAN 1 New Year's Day Bank Holiday
# leads to two Boxing holidays on Dec 26 in other cases
holiday either fixed DEC 26 or if SAT,SUN then float 1 MON after DEC 26 Boxing Day Bank Holiday
# leads to two Christmas holidays on Dec 25 in other cases
holiday either fixed DEC 25 or if SAT,SUN then float 1 TUE after DEC 25 Christmas Day Bank Holiday
Changed API
introduction: conditional holidays and holidays with alternative date
I am currently testing this holiday library, and I configured US Independence Day like this:
holiday either JUL 4 or if SUN then fixed JUL 5 Independence Day
holiday either JUL 4 or if Sat then fixed JUL 3 Independence Day
However, the result for Year 2026 Jul 4 is mis-parsed as Jul 5. (Jul 3 is expected).
I debugged into the code, and found this place has an issue:
HolidayMatcher.java
public ConditionBuilder createConditionBuilder(Matcher matcher) {
return new ConditionBuilder()
.withDaysOfWeek(daysOfWeek(matcher.group(Patterns.PIVOT_DAYS_OF_WEEK_GROUP)))
.withPivotDate(monthDay(
matcher.group(Patterns.**MONTH_GROUP_2**), matcher.group(Patterns.**DAY_GROUP_2**)));
}
In this code, the matcher should use Patterns.MONTH_GROUP and Patterns.DAY_GROUP instread.
Kindly check or if I can fix with a pull request?
Thanks
Some links for inspiration:
more
How to get started?
How to add holiday definitions?
How to ask for holidays?
import
class MyClass {
public get() {
}
}
and
Currently months are identified by their number, e.g. 12 for December.
holiday float 4 SUN before 12 24 1. Advent
Request: Support months to be identified alternatively by their names, e.g. "December".
holiday float 4 SUN before December 24 1. Advent
Required for some holidays in China and Japan
Currently:
holiday either 4 27 or if SUN then fixed 4 26 Koningsdag
Proposal:
holiday either fixed 4 27 or if SUN then fixed 4 26 Koningsdag
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.