Home > Domino Tips > Developer > LotusScript > Calculate U.S. holidays for any given year
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

LOTUSSCRIPT

Calculate U.S. holidays for any given year


Cesar Mugnatto
04.19.2004
Rating: -4.10- (out of 5) Hall of fame tip of the month winner


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


This piece of code was written -- just as a starting point -- to perhaps, at some point, add holidays to your server's holiday list. This code is for the U.S. only.

Option Public
Option Declare

Public Type Holiday
 Name As String
 Date As Variant
End Type

Sub Initialize

'See: http://www.vpcalendar.net/Holiday_Dates/Holiday_Determinations.html

 Dim holidays(17) As Holiday

 Dim tmpString As String
 Dim tmpDate As Variant
 Dim wkDay As Integer
 Dim holidayYear As Integer

 tmpString = Inputbox$("Enter year for 
list of USA holidays dates for 
that year")
 On Error Goto errHandler
 holidayYear = Cint(tmpString)
 tmpString = ""

 '===================================
 holidays(0).Name = "New Year's Day"
 'January 1 - Always
 tmpDate = Dateserial(holidayYear, 1, 1)
 holidays(0).Date = tmpDate
 '===================================

 '===================================
 holidays(1).Name = "Martin Luther King Jr Day"
 '3rd Monday in January - this means it can fall
 anywhere between Jan.
15 and Jan. 21
 tmpDate = Dateserial(holidayYear, 1, 15)
 wkDay = Weekday(tmpDate)
 holidays(1).Date = tmpDate - wkDay + 
2 'Subtract the current day, add 2
for Monday
 If wkDay > 2 Then
  holidays(1).Date = holidays(1).Date + 7 
'Add 7 to go to next
week
 End If
 '===================================

 '===================================
 holidays(2).Name = "Groundhog Day"
 'February 1 - Always
 tmpDate = Dateserial(holidayYear, 2, 2)
 holidays(2).Date = tmpDate
 '===================================

 '===================================
 holidays(3).Name = "Valentine's Day"
 'February 14 - Always
 tmpDate = Dateserial(holidayYear, 2, 14)
 holidays(3).Date = tmpDate
 '===================================

 '===================================
 holidays(4).Name = "President's Day"
 '3rd Monday in February - this means it can 
fall anywhere between Feb.
15 and Feb. 21
 tmpDate = Dateserial(holidayYear, 2, 15)
 wkDay = Weekday(tmpDate)
 holidays(4).Date = tmpDate - wkDay + 2 
'Subtract the current day, add 2
for Monday
 If wkDay > 2 Then
  holidays(4).Date = holidays(4).Date + 7 
'Add 7 to go to next
week
 End If
 '===================================

 '===================================
 holidays(5).Name = "St. Patrick's Day"
 'March 17 - Always
 tmpDate = Dateserial(holidayYear, 3, 17)
 holidays(5).Date = tmpDate
 '===================================

 '===================================
 holidays(7).Name = "Easter"
 holidays(7).Date = dateEaster(holidayYear)
 '===================================

 '===================================
 holidays(6).Name = "Good Friday"
 holidays(6).Date = holidays(7).Date - 2 
'Easter Sunday - 2 days for 
Good Friday
 '===================================

 '===================================
 holidays(8).Name = "Mother's Day"
 '2nd Sunday in May - this means it can fall 
anywhere between May 8 and 
May 14
 tmpDate = Dateserial(holidayYear, 5, 8)
 wkDay = Weekday(tmpDate)
 holidays(8).Date = tmpDate - wkDay + 1 
'Subtract the current day, add 1
for Sunday
 If wkDay > 1 Then
  holidays(8).Date = holidays(8).Date + 7 
'Add 7 to go to next
week
 End If
 '===================================

 '===================================
 holidays(9).Name = "Memorial Day"
 'Last Monday in May - this means it can fall 
anywhere between May 25 
and May 31
 tmpDate = Dateserial(holidayYear, 5, 25)
 wkDay = Weekday(tmpDate)
 holidays(9).Date = tmpDate - wkDay + 2 
'Subtract the current day, add 2
for Monday
 If wkDay > 2 Then
  holidays(9).Date = holidays(9).Date + 7 
'Add 7 to go to next 
week
 End If
 '===================================

 '===================================
 holidays(10).Name = "Father's Day"
 '3rd Sunday in June - this means it can fall 
anywhere between June 15 
and June 21
 tmpDate = Dateserial(holidayYear, 6, 15)
 wkDay = Weekday(tmpDate)
 holidays(10).Date = tmpDate - wkDay + 1 
'Subtract the current day, add 
1 for Sunday
 If wkDay > 1 Then
  holidays(10).Date = holidays(10).Date + 7
 'Add 7 to go to next
week
 End If
 '===================================

 '===================================
 holidays(11).Name = "Independence Day"
 'July 4 - Always
 tmpDate = Dateserial(holidayYear, 7, 4)
 holidays(11).Date = tmpDate
 '===================================

 '===================================
 holidays(12).Name = "Labor Day"
 '1st Monday in September - this means it can 
fall anywhere between
Sept. 1 and Sept. 7
 tmpDate = Dateserial(holidayYear, 9, 1)
 wkDay = Weekday(tmpDate)
 holidays(12).Date = tmpDate - wkDay + 2 
'Subtract the current day, add 
2 for Monday
 If wkDay > 2 Then
  holidays(12).Date = holidays(12).Date + 7
 'Add 7 to go to next
week
 End If
 '===================================

 '===================================
 holidays(13).Name = "Columbus Day"
 '2nd Monday in October - this means it can 
fall anywhere between Oct. 8 
and Oct. 14
 tmpDate = Dateserial(holidayYear, 10, 8)
 wkDay = Weekday(tmpDate)
 holidays(13).Date = tmpDate - wkDay + 2 
'Subtract the current day, add
2 for Monday
 If wkDay > 2 Then
  holidays(13).Date = holidays(13).Date + 7 
'Add 7 to go to next
week
 End If
 '===================================

 '===================================
 holidays(14).Name = "Halloween"
 'October 31 - Always
 tmpDate = Dateserial(holidayYear, 10, 31)
 holidays(14).Date = tmpDate
 '===================================

 '===================================
 holidays(15).Name = "Veteran's Day"
 'November 11 - Always
 tmpDate = Dateserial(holidayYear, 11, 11)
 holidays(15).Date = tmpDate
 '===================================

 '===================================
 holidays(16).Name = "Thanksgiving"
 '4th Thursday in November - this means it can
 fall anywhere between
Nov. 22 and Nov. 28
 tmpDate = Dateserial(holidayYear, 11, 22)
 wkDay = Weekday(tmpDate)
 holidays(16).Date = tmpDate - wkDay + 5 
'Subtract the current day, add
5 for Thursday
 If wkDay > 5 Then
  holidays(16).Date = holidays(16).Date + 7 
'Add 7 to go to next
week
 End If
 '===================================

 '===================================
 holidays(17).Name = "Christmas Day"
 'December 25 - Always
 tmpDate = Dateserial(holidayYear, 12, 25)
 holidays(17).Date = tmpDate
 '===================================

 Forall h In holidays
  tmpString = tmpString & Chr(13) & 
Format(h.Date, "yyyy.mm.dd")
& Chr(9) & h.Name
 End Forall

 Msgbox Mid$(tmpString, 2), , "USA Holidays for " 
& Cstr(holidayYear)

 Goto endFunc

errHandler:
 Msgbox "Invalid year entered"
 Resume endFunc

endFunc:
End Sub

Function dateEaster(y As Integer) As Variant

'See http://aa.usno.navy.mil/faq/docs/easter.html

 Dim c As Integer
 Dim n As Integer
 Dim k As Integer
 Dim i As Integer
 Dim j As Integer
 Dim l As Integer
 Dim m As Integer
 Dim d As Integer

c = y \ 100
n = y - 19 * ( y \ 19 )
k = ( c - 17 )  25
i = c - c \ 4 - ( c - k ) \ 3 +
 19 * n + 15
i = i - 30 * ( i \ 30 )
i = i - ( i \ 28 ) * ( 1 - ( i \ 28 ) 
* ( 29 \ ( i + 1 ) ) * 
( ( 21 - n ) \ 11 ) )
j = y + y  4 + i + 2 - c + c \ 4
j = j - 7 * ( j \ 7 )
l = i - j
m = 3 + ( l + 40 ) \ 44
d = l + 28 - 31 * ( m \ 4 )



 dateEaster = Dateserial(y, m, d)

End Function

Do you have comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip exchange by member Cesar Mugnatto. Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our monthly tip contest and you could win a prize and a spot in our Hall of Fame.

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
LotusScript
Display a custom message box using a LotusScript-generated button
Debug Lotus Notes documents using extracted data
Extracting attachments from a Lotus Notes rich-text field
Programmatically replace the design of Lotus Notes databases
Reading a binary field in an Oracle database with LotusScript
LotusScript equivalent of @Picklist for Lotus Notes
Launch large attachments within an email from a Notes database
How to find files on a hard drive or mapped network with LotusScript
Update the ACL from the Roles view with LotusScript
LotusScript agent moves tagged spam email to junk mail folder

LotusScript
Display a custom message box using a LotusScript-generated button
Can I use LotusScript to merge cells in a Microsoft Word table?
Debug Lotus Notes documents using extracted data
Extracting attachments from a Lotus Notes rich-text field
Programmatically replace the design of Lotus Notes databases
Reading a binary field in an Oracle database with LotusScript
LotusScript equivalent of @Picklist for Lotus Notes
Launch large attachments within an email from a Notes database
How to find files on a hard drive or mapped network with LotusScript
Update the ACL from the Roles view with LotusScript

Lotus Notes Domino Calendar and Contact Management
Synchronize LinkedIn contacts with Lotus Notes Domino
Setting up Rooms and Resources in Lotus Notes Domino 7
Daylight Saving Time 2007 -- seven helpful tips for Lotus Notes administrators
Top 10 Notes/Domino administration tips of 2006
Top 10 Domino administration tips of 2005
Can blank rows in calendar view be suppressed for readers not specified in reader field?
Besides automating administration, Release 7.0 enhances the client side as well
Automatic deletion of dead mail in mail.box
Make only selected To Dos show up on calendar
Error: 'Invalid or nonexistent document'

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.

HomeNewsTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 1999 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts