Calendars

R

RayL

I have a calendar related project. Can anyone tell me where I can find
an explanation for the occurence of various holidays? What I mean is
how to know when they will occur for future dates.

Thanks,
Ray
 
J

Jeff

I no longer have a bookmark to my source for these rules, but I've
been using the following code in a database stored procedure for
several years now. The procedure returns the letter "M" for a major
holiday, or "B" for just a bank holiday. Jan to Dec = 1 to 12, Sun to
Sat = 0 to 6. Even if you don't know SPL, it should be easy enough
to translate to Java.

Of course, this is assuming that you are talking about American holidays...

create procedure holiday(d date) returning char(1);

define month int;
define day int;
define week int;
define weekday int;
define i date;

let month = month(d);
let day = day(d);
let weekday = weekday(d);
let week = ((day(d) - 1)/7) + 1;

if (month = 1 and day = 1) then
return "M"; -- New Years
elif (month = 1 and weekday = 1 and week = 3) then
return "B"; -- MLK
elif (month = 2 and weekday = 1 and week = 3) then
return "B"; -- Presidents
elif (month = 5 and weekday = 1 and day > 24) then
return "M"; -- Memorial
elif (month = 7 and day = 4) then
return "M"; -- Independence
elif (month = 9 and weekday = 1 and week = 1) then
return "M"; -- Labor
elif (month = 10 and weekday = 1 and week = 2) then
return "B"; -- Columbus
elif (month = 11 and weekday = 4 and week = 4) then
return "M"; -- Thanksgiving
elif (month = 12 and day = 25) then
return "M"; -- Christmas
end if;

return "";

end procedure;
 
D

David Segall

Jeff said:
I no longer have a bookmark to my source for these rules, but I've
been using the following code in a database stored procedure for
several years now. The procedure returns the letter "M" for a major
holiday, or "B" for just a bank holiday. Jan to Dec = 1 to 12, Sun to
Sat = 0 to 6. Even if you don't know SPL, it should be easy enough
to translate to Java.

Of course, this is assuming that you are talking about American holidays...

create procedure holiday(d date) returning char(1);

define month int;
define day int;
define week int;
define weekday int;
define i date;

let month = month(d);
let day = day(d);
let weekday = weekday(d);
let week = ((day(d) - 1)/7) + 1;

if (month = 1 and day = 1) then
return "M"; -- New Years
elif (month = 1 and weekday = 1 and week = 3) then
return "B"; -- MLK
elif (month = 2 and weekday = 1 and week = 3) then
return "B"; -- Presidents
elif (month = 5 and weekday = 1 and day > 24) then
return "M"; -- Memorial
elif (month = 7 and day = 4) then
return "M"; -- Independence
elif (month = 9 and weekday = 1 and week = 1) then
return "M"; -- Labor
elif (month = 10 and weekday = 1 and week = 2) then
return "B"; -- Columbus
elif (month = 11 and weekday = 4 and week = 4) then
return "M"; -- Thanksgiving
elif (month = 12 and day = 25) then
return "M"; -- Christmas
end if;

return "";

end procedure;
Don't Americans have Easter Holidays?
 
B

Brad BARCLAY

RayL said:
I have a calendar related project. Can anyone tell me where I can find
an explanation for the occurence of various holidays? What I mean is
how to know when they will occur for future dates.

I don't know of such a site. What you might want to do instead is to
list out the fixed dates you need (ie: things that occur on a specific
date each year, like New Years Day, Christmas Day, Boxing Day, Canada
Day, etc.), and then see what's left in the "variable" column (Easter
comes to mind -- something like the first full moon after Lent? I'm not
completely sure -- I'm neither Christian nor Catholic), and look them up
specifically.

Brad BARCLAY
 
R

Roedy Green

Don't Americans have Easter Holidays?

package com.mindprod.holidays;

// com.mindprod.holidays.EasterSunday
import com.mindprod.business.BigDate;

/**
* Specific holiday calculator
*/

public class EasterSunday extends HolInfo
{

public String getAuthority()
{
return "Felix Gursky\'s interpretation of:\n"
+ " 1. Christophorus Clavius: Calendarium Gregorianum
Perpetuum.\n"
+ " Cum Summi Pontificis Et Aliorum Principum. Romae, Ex
Officina\n"
+ " Dominicae Basae, MDLXXXII, Cum Licentia Superiorum.\n"
+ " 2. Christophorus Clavius: Romani Calendarii A Gregorio
XIII.\n"
+ " Pontifice Maximo Restituti Explicatio. Romae,
MDCIII.;\n";
}
public int getFirstYear(int base)
{
return 30;
}
public String getName()
{
return "Easter Sunday";
}
public String getRule()
{
return
"The first Sunday after the first full moon after the vernal
equinox.";
}
public int when( int year, boolean shift, int base )
{
if ( !isYearValid(year, base) )
{
return BigDate.NULL_ORDINAL;
}

if ( year <= 1582 )
{
// use the old Julian method described in
// Oudin (1940) as quoted in
// Explanatory Supplement to the Astronomical Almanac, P.
Kenneth Seidelmann, editor.
// picked off the web at
http://www.pip.dknet.dk/~pip10160/cal/node3.html
// calc g golden number - 1;
int g = year % 19;
// calc i the number of days from 21 March to the Paschal
full moon
int i = ((19 * g) + 15) % 30;
// calc j the weekday for the Paschal full moon (0=Sunday,
1=Monday)
int j = (year + year/4 + i) % 7;
// calc l the number of days from 21 March to the Sunday
// on or before the Paschal full moon (a number between -6
and 28)
int l = i - j;
// calc Easter month
int mm = 3 + (l+40)/44;
// calc Easter day of month.
int dd = l + 28 - 31 * (mm/4);
int ord = BigDate.toOrdinal(year, mm, dd);
return shiftSatToFriSunToMon(ord, shift);

}
else if ( year >= 1583 )
{
// more elaborate Gregorian method.
int yearIn19YearCycle = (year % 19) + 1;
int century = year/100 + 1;
int x =(3*century)/4 - 12;
int z = (8*century + 5)/25 - 5;
int d = 5*year/4 - x - 10;
int e = (11*yearIn19YearCycle + 20 + z - x) % 30;
if ( ((e == 25) && (yearIn19YearCycle > 11)) || (e == 24) )
{
e++;
}
int n = 44 - e;
if ( n < 21 )
{
n += 30;
}

n += 7 - ((d + n) % 7);
int ord;
if ( n <= 31 )
{
ord = BigDate.toOrdinal(year, 3, n);
}
else
{
ord = BigDate.toOrdinal(year, 4, n-31);
}

return shiftSatToFriSunToMon(ord, shift);
}return BigDate.NULL_ORDINAL;
} // end when.
}
 
R

RayL

Thanks to all. I also found JavaWorld Java Tip 44 (I would give you the
URL but I saved the file in .mht format, which is only used by Microsoft
IE and I'm using Linux for email.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top