Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Tue Oct 17, 2017 2:59 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Calculate Major U.S. Holidays
PostPosted: Sat May 26, 2012 1:06 pm 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
FUNCTION HOLIDAY(year as integer,Holiday_Name as string) as DATE
Dim dt As New date
Dim h As Integer
Dim i As Integer
Dim j As Integer
Dim l As Integer
Dim m As Integer
Dim d As Integer
//
If year<1900 Or year>2099 Then Return Nil
dt.day=1
Select Case holiday_name
Case "NEW YEAR"
dt.month=1
//
Case "4th of July" ' duh
dt.month=7
dt.Day=4
//
Case "Christmas"
dt.month=12
dt.day=25
//
Case "LABOR DAY" ' 1st Monday in September
dt.month=9
First_Monday(dt)
//
Case "Martin Luther King","MLK" ' 3rd Monday in January
dt.month=1
First_Monday(dt)
dt.day=dt.day+14
//
Case "PRESIDENTS DAY" ' 3rd Monday in February
dt.month=2
First_Monday(dt)
dt.day=dt.day+14
//
Case "COLUMBUS DAY" ' 2nd Monday in October
dt.month=10
First_Monday(dt)
dt.day=dt.day+7
//
Case "VETERANS DAY" ' 4th Monday in October
dt.month=10
First_Monday(dt)
dt.day=dt.day+21
//
case "THANKSGIVING" ' 4th Thursday in November
dt.Month=11
First_Monday(dt)
dt.day=dt.day-4 ' back up to thursday
if dt.Month<>11 then dt.day=dt.day+7 ' 1st Thurs
dt.day=dt.day+21
//
case "MEMORIAL DAY" ' Last Monday in May
dt.month=6 ' get 1st Monday in JUNE
First_Monday(dt)
dt.day=dt.day-7 ' back up to last Monday in May
//
Case "EASTER"
H = (24 + 19*(year Mod 19)) Mod 30
I = H - (H\28)
J = (year + year\4 + I - 13) Mod 7
L = I - J
m = 3 + (L + 40)\44
d= L + 28 - 31*(m\4)
dt.year=year
dt.month=m
dt.day=d
//
Case "GOOD FRIDAY"
dt.totalseconds=HOLIDAY(year,"EASTER").TotalSeconds
dt.day=dt.day-2
//
Case "ASH WEDNESDAY"
dt.totalseconds=HOLIDAY(year,"EASTER").TotalSeconds
dt.day=dt.day-46
Case Else
Return Nil
End Select
Return dt
END FUNCTION


SUB First_Monday(byref dt AS Date)
Dim d As Integer
d=dt.DayOfWeek ' 1=Sun
Select Case dt.DayOfWeek
Case 1
d=1
Case 2
d=0
Case Else
d=9-d
End Select
dt.day=dt.day+d
END SUB

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Calculate Major U.S. Holidays
PostPosted: Sat May 26, 2012 9:48 pm 
Offline
User avatar

Joined: Sun Aug 12, 2007 10:10 am
Posts: 1086
Location: Boiling Springs, SC
Awesome :-) Here's a complete list of holiday and date conversions including Gregorian calculations and hebrew holidays:-) ...very little needed to port to RB

http://www.tek-tips.com/faqs.cfm?fid=5185

Thanks!

_________________
Matthew A. Combatti
Real Studio 2012 r1.2

Visit Xojo Developer's Spot!
Systems I Use:
Windows XP/Windows Vista/Windows Server 2008 r2/Windows 7/Windows 8
Mac OSX 10.5/Mac OSX 10.6/Mac OSX Server/Ubuntu/Debian/Suse/Red Hat/
Windows Server 2011/CentOS 5.4 /ReactOS/SimOS

~All Xojo Compatible~


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group