Giter Club home page Giter Club logo

holiday-calculator's People

Contributors

ckunki avatar dependabot[bot] avatar kaklakariada avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

holiday-calculator's Issues

Add calculator for orthodox Eastern

/**
 * (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);
		}
}

Add support for Finnish holidays Candlemas and Feast of the Annunciation

  • Kynttilänpäivä
  • ilmestyspäivä

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

  • a pivot date: holiday float 1 SUN after 2 2 Kynttilänpäivä
  • but only use pivot date, if not equal to holiday easter -49
  • otherwise use holiday easter -56

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

  • a pivot date: holiday float 1 Sun after MAR 22 Marian ilmestyspäivä
  • but only use pivot date, if not equal to holiday easter 0 or holiday easter -7
  • otherwise use holiday easter -14

potential syntax
holiday either float 1 Sun after MAR 22 of if equal to easter 0,easter -7 then easter -14 Kynttilänpäivä

Add support for conditional holidays

e.g. UK and Netherlands have cases in which

  • the holiday is on a fixed date
  • except if the date is a specific day of week then the holiday is some days off, e.g. on a Monday

Examples

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

Ideas for configuration file syntax

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

Enhance README.md

Changed API
introduction: conditional holidays and holidays with alternative date

The 'either' statement is incorrectly parsed via cfg

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

Add holiday definition files for countries

Enable month names in configuration file

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.