Calendars

Discussion in 'Java' started by RayL, Sep 20, 2003.

  1. RayL

    RayL Guest

    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
     
    RayL, Sep 20, 2003
    #1
    1. Advertising

  2. RayL

    Jeff Guest

    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;


    --
    Jeff
    jlar310 at yahoo


    "RayL" <> wrote in message news:eUZab.298992$...
    > 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
    >
     
    Jeff, Sep 20, 2003
    #2
    1. Advertising

  3. RayL

    David Segall Guest

    "Jeff" <> wrote:

    >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?
     
    David Segall, Sep 20, 2003
    #3
  4. RayL

    Brad BARCLAY Guest

    RayL wrote:
    > 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

    --
    =-=-=-=-=-=-=-=-=
    From the OS/2 WARP v4.5 Desktop of Brad BARCLAY.
    The jSyncManager Project: http://www.jsyncmanager.org
    
     
    Brad BARCLAY, Sep 20, 2003
    #4
  5. RayL

    Roedy Green Guest

    On Sat, 20 Sep 2003 14:56:10 GMT, RayL <>
    wrote or quoted :

    >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.


    see http://mindprod.com/holidays.html

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Sep 20, 2003
    #5
  6. RayL

    Roedy Green Guest

    On Sat, 20 Sep 2003 15:57:26 GMT, David Segall <>
    wrote or quoted :

    >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.
    }

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Sep 20, 2003
    #6
  7. RayL

    RayL Guest

    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.

    Roedy Green wrote:
    > On Sat, 20 Sep 2003 14:56:10 GMT, RayL <>
    > wrote or quoted :
    >
    >
    >>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.

    >
    >
    > see http://mindprod.com/holidays.html
    >
    > --
    > Canadian Mind Products, Roedy Green.
    > Coaching, problem solving, economical contract programming.
    > See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    RayL, Sep 20, 2003
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Holyer
    Replies:
    0
    Views:
    1,992
    Andy Holyer
    Apr 12, 2006
  2. Antoni Massó Mola

    C# & Calendars

    Antoni Massó Mola, May 3, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    3,118
    Peter Blum
    May 3, 2004
  3. =?Utf-8?B?TWFyaWFubyBQYWRpbGxh?=

    One of 12 Calendars DayRender event does not work on PostBack

    =?Utf-8?B?TWFyaWFubyBQYWRpbGxh?=, Nov 29, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    621
    =?Utf-8?B?TWFyaWFubyBQYWRpbGxh?=
    Nov 29, 2005
  4. =?Utf-8?B?TWFyaWFubyBQYWRpbGxh?=

    One of 12 Calendars DayRender event does not work on PostBac

    =?Utf-8?B?TWFyaWFubyBQYWRpbGxh?=, Dec 28, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    644
    =?Utf-8?B?TWFyaWFubyBQYWRpbGxh?=
    Jan 28, 2006
  5. Eddie
    Replies:
    0
    Views:
    324
    Eddie
    Jul 11, 2006
Loading...

Share This Page