About This Code
Brief Description:
to check for weekends, Specific holidays and leap years
Contributor:
Roche Olivier
Type:
Date/Time functions
Notes Version:
R5.x, R6.x
Last Modified:
10 Jun 2003
OpenNTF Disclaimer
All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.
Code / Description
This is a function which you can use to loop through a list of dates and then see if they are legal working days.
I use this code currently to check on validity of days booked for leave to only create valid entries on the database.
Usage / Example
The calling function:(IsValid)
==============================
'RemStartDate will be the date you need to pass to the function, as well as the document you are currently working with.
Function IsValid(RemStartDate As notesdatetime,doc As notesdocument) As Variant
If isWeekday(RemStartDate)=True And isNotHoliday(RemStartDate,doc)=True Then
IsValid = True
else
IsValid = False
End If
End Function
To check Sat&Sun is weekend :(IsWeekday)
========================================
Function IsWeekday(RemStartDate As notesdatetime) As Variant
Dim dayofweek As Integer
dayofweek =Weekday(RemStartDate.LsLocalTime)
If (dayofweek = 1) Or (dayofweek = 7) Then
IsWeekday = False
Exit Function
End If
IsWeekday = True
End Function
IsNotHoliday
============
You need to create a profile document with the name "Setup" and create a field on the document that is a multivalue field with the name "Holidays", you can then populate the Holidays field with all your holidays, or invalid days depending on what you want to use the function.
Function IsNotHoliday(RemStartDate As notesdatetime,doc As notesdocument) As Variant
Dim session As New notessession
Dim db As notesdatabase
Set db = session.currentdatabase
Dim profdoc As notesdocument
Set profdoc = db.getprofiledocument("Setup")
Dim i As Integer
Dim s As notesitem
Dim tmp() As String
Dim LookupDate As notesdatetime
Set s=Profdoc.getfirstitem("Holidays")
Dim tmpstring As String
i = 1
Forall x In s.values
Set LookupDate = New notesdatetime(x)
Redim Preserve tmp(i)
tmp(i) = CstrLookupDate.LSLocalTime)
tmpstring = tmp(i)
If (Cstr(RemStartDate.LSLocalTime) = TmpString) Then
IsNotHoliday = False
Exit Function
End If
i = i + 1
End Forall
IsNotHoliday = True
End Function