Package PKG_CALC_HOLIDAYS

Package Specification

create or replace package pkg_calc_holidays 
as
  procedure p_print_holidays ( p_year in number );
end;

Package Body

create or replace package body pkg_calc_holidays 
as
  procedure p_print ( p_string varchar2 )
  is
  begin
    dbms_output.put_line ( p_string );
  end p_print;

  function f_calc_easter ( a in number )
    return date
  is
    g number    := mod(a,19)+1;           /* golden number */
    c number    := floor(a/100)+1;        /* century */
    x number    := floor(3*c/4)-12;       /* correction for non leap years */
    y number    := floor(((8*c)+5)/25)-5; /* moon correction */
    z number    := floor(5*a/4)-10-x;     /* Sunday */
    m number(2) := 3;                     /* March */
  
    e number;                             /* epacta */
    n number;                             /* full moon */
    p number(2);                          /* Easter Sunday */ 
  begin
    /* calculate epacta */
    e := mod(((11*g)+20+y-x),30); 
  
    if ( (e = 24 or e = 25) and g > 11 )
    then
      e := e + 1;
    end if;
  
    /* calculate full moon */
    n := 44-e;
  
    if ( n < 21 )
    then
      n := n + 30;
    end if;
  
    /* calculate Easter Sunday */
    p := n+7-mod((z+n),7);
  
    if ( p > 31 ) 
    then
      p := p - 31;
      m := m + 1;
    end if;

    /* return Easter Sunday as a date */
    return to_date( a||'-'||m||'-'||p, 'yyyy-mm-dd' );
  end f_calc_easter;

  procedure p_print_holidays ( p_year in number )
  is
    g_easter date;
  begin
    /* calculate Easter Sunday */
    g_easter := f_calc_easter ( p_year );

    /* calculate and print holidays to screen */ 
    p_print ('Goede Vrijdag:   '||to_char(g_easter-2,'dd-mm-yyyy'));
    p_print ('Paaszondag:      '||to_char(g_easter,'dd-mm-yyyy'));
    p_print ('Paasmaandag:     '||to_char(g_easter+1,'dd-mm-yyyy'));
    p_print ('Hemelvaart:      '||to_char(g_easter+39,'dd-mm-yyyy'));
    p_print ('Pinksterzondag:  '||to_char(g_easter+49,'dd-mm-yyyy'));
    p_print ('Pinkstermaandag: '||to_char(g_easter+50,'dd-mm-yyyy'));
  end p_print_holidays;
end pkg_calc_holidays;