For Programmers: Free Programming Magazines  


Home > Archive > Clipper > June 2004 > US holidays









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author US holidays
Stephan Koenig

2004-06-09, 3:55 am

Hi,

is there any function to determin if a specific day is a holiday ?

I am aware that I could enter all of them every year, just checking if there
is any other way.

Thanks

Stephan
www.toner.com


Stephan Koenig

2004-06-09, 3:55 am

I forgot, I need this to run under alaska xbase


Richard Bos

2004-06-09, 3:55 am

"Stephan Koenig" <NO_SK_SPAM@Toner.com> wrote:

> is there any function to determin if a specific day is a holiday ?
>
> I am aware that I could enter all of them every year, just checking if there
> is any other way.


For some, yes. That is, there's no built-in function, and none that I am
aware of in a library, but they can be written without too much trouble.
Christmas is always on the same day. Easter calculation is notoriously
involved, but could certainly be done; a full explanation is in the
Calendar FAQ at <http://www.tondering.dk/claus/cal/calendar26.html>.

Some holidays, however, are TTBOMK hand-picked at most a couple of years
in advance (e.g., IIRC, some bank holidays in the UK), and some depend
on astronomical observation by officials (see the Islamic section in the
Calendar FAQ. Moreover, many of the variable holidays are specific to a
country; not even Scotland and England have the same official holidays.

So it really depends on which holidays you want. If it's just the common
Christian ones, you can certainly write code which checks for them.
Obviously, so do things like the 14th of July, but nobody outside the
country of origin is likely to be interested in those; if your program
is just for local firms, that's no problem, of course. Some holidays you
will continue to have to enter by hand.

Richard
Dave Pearson

2004-06-09, 8:55 am

* Richard Bos <rlb@hoekstra-uitgeverij.nl>:

> "Stephan Koenig" <NO_SK_SPAM@Toner.com> wrote:
>
>
> For some, yes. That is, there's no built-in function, and none that I am
> aware of in a library, but they can be written without too much trouble.
> Christmas is always on the same day. Easter calculation is notoriously
> involved, but could certainly be done; a full explanation is in the
> Calendar FAQ at <http://www.tondering.dk/claus/cal/calendar26.html>.


The NanFor library has a function for doing this calculation:

,----
| FT_EASTER()
| Return the date of Easter
| ------------------------------------------------------------------
|
| Syntax
|
| FT_EASTER( <xYear> ) -> dEdate
|
| Arguments
|
| xYear can be a character, date or numeric describing the year
| for which you wish to receive the date of Easter.
|
| Returns
|
| The actual date that Easter occurs.
`----

which should work as long as easter dances around the calendar like a
drunken uncle at a family party.

> Some holidays, however, are TTBOMK hand-picked at most a couple of years
> in advance (e.g., IIRC, some bank holidays in the UK), and some depend on
> astronomical observation by officials (see the Islamic section in the
> Calendar FAQ. Moreover, many of the variable holidays are specific to a
> country; not even Scotland and England have the same official holidays.


Calendrical Calculations <URL:http://www.calendarists.com/> is a great read
for anyone interested in this sort of thing.

--
Dave Pearson | OSLib - Timeslice release functions.
http://www.davep.org/ | eg - Norton Guide reader for Linux.
http://www.davep.org/clipper/ | weg - Norton Guide reader for Windows.
http://www.davep.org/norton-guides/ | dgscan - DGROUP scanner for Clipper.
Stephan Koenig

2004-06-09, 8:55 am

thanks for your answer

> So it really depends on which holidays you want


I am looking for US bank holidays, I am German, so I do not know all of
them.


Stephan Koenig

2004-06-09, 3:55 pm

exept Easter, are this the only "US Holidays" ?

(Freight copmanies closes, warehouses closed and so on)



New Year's Day, January 1st.
Birthday of Martin Luther King, third Monday in January.
Memorial Day, last Monday in May
United States of America's Independence Day, July 4.
Labor Day, first Monday in September.
Thanksgiving Day, fourth Thursday in November.
Christmas Day, December 25th.




Gary

2004-06-10, 8:55 pm

On 9-Jun-2004, "Stephan Koenig" <NO_SK_SPAM@Toner.com> wrote:

> exept Easter, are this the only "US Holidays" ?
>
> (Freight copmanies closes, warehouses closed and so on)
>
> New Year's Day, January 1st.
> Birthday of Martin Luther King, third Monday in January.
> Memorial Day, last Monday in May
> United States of America's Independence Day, July 4.
> Labor Day, first Monday in September.
> Thanksgiving Day, fourth Thursday in November.
> Christmas Day, December 25th.


The 10 Arizona State Holidays (should be good for US, too; maybe?) are:

New Year's Day, January 1st.
Martin Luther King Day, 3rd Monday in January.
President's Day - 3rd Monday in February
Memorial Day, 4th Monday in May
Independence Day, July 4.
Labor Day, 1st Monday in September.
Columbus Day - 2nd Monday in October
Veteren's Day - November 11th
Thanksgiving Day, 4th Thursday in November.
Christmas Day, December 25th.

Any holiday that falls on a Saturday is moved to the previous day (Friday).
Any holiday that falls on a Sunday is moved to the next day (Monday).

Program code to calculate these dates would be appreciated. Then, I
wouldn't require my users maintain the "Holiday" database! Maybe we all can
work together! (What a novel concept!) (Will SCO sue us?) (I love
parentheses!)

Gary
Clifford Wiernik

2004-06-11, 3:55 pm

This appears to be correct. The previous post omitted Columbus,
Veterans and Presidents Day.

Gary wrote:
> On 9-Jun-2004, "Stephan Koenig" <NO_SK_SPAM@Toner.com> wrote:
>
>
>
>
> The 10 Arizona State Holidays (should be good for US, too; maybe?) are:
>
> New Year's Day, January 1st.
> Martin Luther King Day, 3rd Monday in January.
> President's Day - 3rd Monday in February
> Memorial Day, 4th Monday in May
> Independence Day, July 4.
> Labor Day, 1st Monday in September.
> Columbus Day - 2nd Monday in October
> Veteren's Day - November 11th
> Thanksgiving Day, 4th Thursday in November.
> Christmas Day, December 25th.
>
> Any holiday that falls on a Saturday is moved to the previous day (Friday).
> Any holiday that falls on a Sunday is moved to the next day (Monday).
>
> Program code to calculate these dates would be appreciated. Then, I
> wouldn't require my users maintain the "Holiday" database! Maybe we all can
> work together! (What a novel concept!) (Will SCO sue us?) (I love
> parentheses!)
>
> Gary


Gary

2004-06-11, 8:55 pm


On 10-Jun-2004, "Gary" <garyc57@cableaz.com> wrote:

> The 10 Arizona State Holidays (should be good for US, too; maybe?) are:
>
> New Year's Day, January 1st.
> Martin Luther King Day, 3rd Monday in January.
> President's Day - 3rd Monday in February
> Memorial Day, 4th Monday in May
> Independence Day, July 4.
> Labor Day, 1st Monday in September.
> Columbus Day - 2nd Monday in October
> Veteren's Day - November 11th
> Thanksgiving Day, 4th Thursday in November.
> Christmas Day, December 25th.
>
> Any holiday that falls on a Saturday is moved to the previous day
> (Friday).
> Any holiday that falls on a Sunday is moved to the next day (Monday).
>
> Program code to calculate these dates would be appreciated. Then, I
> wouldn't require my users maintain the "Holiday" database! Maybe we all
> can
> work together! (What a novel concept!) (Will SCO sue us?) (I love
> parentheses!)
>
> Gary


Here's a bit of pseudo-code that just popped into my mind...

FUNCTION GetHoliday( dDate, nDoW, nInstance )
*
* dDate is any day in the month and year we are checking
* nDoW is the day of the w we are after
* nInstance is the number of wdays we want
*
* For example,
* GetHoliday( CTOD( "11/14/2004" ), 5, 4 )
* would give us the 4th Thursday in November, 2004
* GetHoliday( CTOD( "02/15/2005"), 2, 3 )
* would give us the 3rd Monday in February, 2005

LOCAL i := 1

dDate := BOM( dDate )
// BOM() is a function that returns the 1st day of the given month and year.
// I leave this function as an exercise for the reader...

// Now we are looking for the first day in the month
// that equals the day of the w we are after

DO WHILE .T.
IF DOW( dDate ) = nDoW
EXIT
ENDIF
dDate++
ENDDO

// dDate now equals the 1st day of the w
// in the month we are after.

// Now, just add a w at a time, until we get
// the 3rd Monday, or 4th Thursday, etc.

DO WHILE i < nInstance
dDate += 7
i++
ENDDO

RETURN dDate

I hereby release this to the public domain. Credit would be nice, though.

How can we make this better? Error checking?

Thanks for the fun and entertainment,
Gary
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com