View source with formatted comments or as raw
    1/*  Part of SWI-Prolog
    2
    3    Author:        Anne Ogborn
    4    WWW:           http://www.swi-prolog.org
    5
    6    This program is free software; you can redistribute it and/or
    7    modify it under the terms of the GNU General Public License
    8    as published by the Free Software Foundation; either version 2
    9    of the License, or (at your option) any later version.
   10
   11    This program is distributed in the hope that it will be useful,
   12    but WITHOUT ANY WARRANTY; without even the implied warranty of
   13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14    GNU General Public License for more details.
   15
   16    You should have received a copy of the GNU General Public
   17    License along with this library; if not, write to the Free Software
   18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   19
   20    As a special exception, if you link this library with other files,
   21    compiled with a Free Software compiler, to produce an executable, this
   22    library does not by itself cause the resulting executable to be covered
   23    by the GNU General Public License. This exception does not however
   24    invalidate any other reasons why the executable file might be covered by
   25    the GNU General Public License.
   26*/
   27:- module(holidays, [
   28	      todays_holiday/1
   29	  ]).   30
   31:- dynamic current_holiday/2.   32
   33current_holiday(0, none).
   34
   35/**  todays_holiday(-Holiday:atom) is det
   36 *
   37 *  succeeds if Holiday is 'todays holiday'
   38 *
   39 *  This is none on 'ordinary' days, or
   40 *  one of
   41 *
   42 *  april_fools_day
   43 *  christmas
   44 *  koningsdag
   45 *  santiklaas
   46 *
   47 * succeeds only within 12 hours either
   48 * side of April 1
   49 *
   50 * April fools day is a traditional holiday celebrated
   51 * by playing hoaxes and practical jokes. A common form
   52 * of this is to substitute nonsensical information where
   53 * useful info is normally displayed.
   54 *
   55 * Koningsdag is 'Kings day' in the Netherlands
   56 * Santiklaas is St. Nicholas' feast
   57 *
   58 */
   59todays_holiday(Holiday) :-
   60	current_holiday(Time, Holiday),
   61	get_time(Now),
   62	Now - Time < 3600, !.
   63todays_holiday(Holiday) :-
   64	year(Year),
   65	todays_holiday(Year, Holiday),
   66	get_time(Now),
   67	retractall(current_holiday(_, _)),
   68	asserta(current_holiday(Now, Holiday)).
   69
   70todays_holiday(YY, april_fools_day) :-
   71	date_between(YY-03-30, 12:00:00,
   72		     YY-04-02, 12:00:00).
   73todays_holiday(YY, christmas) :-
   74	date_between(YY-12-20, 12:00:00,
   75		     YY-12-27, 12:00:00).
   76todays_holiday(YY, koningsdag) :-
   77	date_between(YY-04-26, 12:00:00,
   78		     YY-04-28, 12:00:00).
   79todays_holiday(YY, santiklaas) :-
   80	date_between(YY-12-05, 12:00:00,
   81		     YY-12-06, 12:00:00).
   82todays_holiday(YY, halloween) :-
   83	date_between(YY-10-30, 12:00:00,
   84		     YY-11-01, 12:00:00).
   85todays_holiday(YY, liberation_day) :-
   86	date_between(YY-05-04, 12:00:00,
   87		     YY-05-06, 12:00:00).
   88todays_holiday(YY, carnival) :-
   89	carnival_date(Start, End),
   90	Start = (YY-_-_),
   91	End   = (YY-_-_),
   92	date_between(Start, 12:00:00,
   93		     End,   12:00:00).
   94todays_holiday(YY, chinese_new_year) :-
   95	chinese_new_year_date(Start, End),
   96	Start = (YY-_-_),
   97	End   = (YY-_-_),
   98	date_between(Start, 12:00:00,
   99		     End,   12:00:00).
  100todays_holiday(_, none).
  101
  102carnival_date(2015-2-15, 2015-2-17).
  103carnival_date(2016-2-07, 2016-2-09).
  104carnival_date(2017-2-26, 2017-2-28).
  105carnival_date(2018-2-11, 2018-2-13).
  106carnival_date(2019-3-03, 2019-3-05).
  107carnival_date(2020-2-23, 2020-2-25).
  108carnival_date(2021-2-14, 2021-2-16).
  109carnival_date(2022-2-27, 2022-2-29).
  110carnival_date(2023-2-19, 2023-2-21).
  111carnival_date(2024-2-11, 2025-2-13).
  112carnival_date(2025-3-02, 2025-3-04).
  113
  114chinese_new_year_date(2015-02-19,2015-02-20).
  115chinese_new_year_date(2016-02-08,2016-02-09).
  116chinese_new_year_date(2017-01-28,2017-01-29).
  117chinese_new_year_date(2018-02-16,2018-02-17).
  118chinese_new_year_date(2019-02-05,2019-02-06).
  119chinese_new_year_date(2020-01-25,2020-01-26).
  120chinese_new_year_date(2021-02-12,2021-02-13).
  121chinese_new_year_date(2022-02-01,2022-02-02).
  122chinese_new_year_date(2023-01-22,2023-01-23).
  123chinese_new_year_date(2024-02-10,2024-02-11).
  124chinese_new_year_date(2025-01-29,2025-01-30).
  125chinese_new_year_date(2026-02-17,2026-02-18).
  126chinese_new_year_date(2027-02-06,2027-02-07).
  127chinese_new_year_date(2028-01-26,2028-01-27).
  128chinese_new_year_date(2029-02-13,2029-02-14).
  129chinese_new_year_date(2030-02-03,2030-02-04).
  130
  131/**
  132 * chinese_new_year_animal(?Year, ?Animal).
  133 *
  134 * Succeeds iff Animal matches the Chinese zodiac animal for Year.
  135 */
  136chinese_new_year_animal(2015, 'Sheep').
  137chinese_new_year_animal(2016, 'Monkey').
  138chinese_new_year_animal(2017, 'Rooster').
  139chinese_new_year_animal(2018, 'Dog').
  140chinese_new_year_animal(2019, 'Pig').
  141chinese_new_year_animal(2020, 'Rat').
  142chinese_new_year_animal(2021, 'Ox').
  143chinese_new_year_animal(2022, 'Tiger').
  144chinese_new_year_animal(2023, 'Rabbit').
  145chinese_new_year_animal(2024, 'Dragon').
  146chinese_new_year_animal(2025, 'Snake').
  147chinese_new_year_animal(2026, 'Horse').
  148chinese_new_year_animal(2027, 'Sheep').
  149chinese_new_year_animal(2028, 'Monkey').
  150chinese_new_year_animal(2029, 'Rooster').
  151chinese_new_year_animal(2030, 'Dog').
  152
  153
  154%%	year(-Year)
  155%
  156%	True when Year is the current year
  157
  158year(Year) :-
  159	get_time(Now),
  160	stamp_date_time(Now, Term, 'UTC'),
  161	date_time_value(year, Term, Year).
  162
  163date_between(SDate, STime, EDate, ETime) :-
  164	get_time(Now),
  165	stamp(SDate, STime, Start),  Now >= Start,
  166	stamp(EDate, ETime, End),    Now =< End.
  167
  168stamp(YY-MM-DD, H:M:S, Time) :-
  169	date_time_stamp(date(YY,MM,DD,H,M,S,0,'UTC',-), Time)