' Author : Interface
' Date : 12-1-2012
' Purpose : Helpmij
'---------------------------------------------------------------------------------------
'/////////////////////////////////////////////////////////////////////////////////
' Holiday function
'/////////////////////////////////////////////////////////////////////////////////
Option Explicit
Function funIsSpecialDay(ByVal oDate As Date) As Boolean
funIsSpecialDay = False
Select Case oDate
Case Is = funEaster1(Year(oDate)) '1e paasdag
funIsSpecialDay = True
Case Is = funEaster2(Year(oDate)) '2e paasdag
funIsSpecialDay = True
Case Is = funPentecost1(Year(oDate)) '1e pinksteren
funIsSpecialDay = True
Case Is = funPentecost2(Year(oDate)) '2e pinksteren
funIsSpecialDay = True
Case Is = funAscension(Year(oDate)) 'hemelvaart
funIsSpecialDay = True
Case Is = funGoodFriday(Year(oDate)) 'Goede vrijdag
funIsSpecialDay = True
Case Is = CDate("31-12-" & Year(oDate)) 'Oud en nieuw
funIsSpecialDay = True
Case Is = CDate("1-1-" & Year(oDate)) 'nieuwjaarsdag
funIsSpecialDay = True
Case Is = CDate("30-4-" & Year(oDate)) 'Koninginnedag
funIsSpecialDay = True
End Select
End Function
Function funWhatSpecialDay(ByVal oDate As Date) As String
If funIsSpecialDay(oDate) = True Then
Select Case oDate
Case Is = funEaster1(Year(oDate)) '1e paasdag
funWhatSpecialDay = "1e Paasdag"
Case Is = funEaster2(Year(oDate)) '2e paasdag
funWhatSpecialDay = "2e Paasdag"
Case Is = funPentecost1(Year(oDate)) '1e pinksteren
funWhatSpecialDay = "1e Pinksterdag"
Case Is = funPentecost2(Year(oDate)) '2e pinksteren
funWhatSpecialDay = "2e Pinksterdag"
Case Is = funAscension(Year(oDate)) 'hemelvaart
funWhatSpecialDay = "Hemelvaartsdag"
Case Is = funGoodFriday(Year(oDate)) 'Goede vrijdag
funWhatSpecialDay = "Goede vrijdag"
Case Is = CDate("31-12-" & Year(oDate)) 'oudejaarsdag
funWhatSpecialDay = "Oudejaarsdag"
Case Is = CDate("1-1-" & Year(oDate)) 'nieuwjaarsdag
funWhatSpecialDay = "Nieuwjaarsdag"
Case Is = CDate("30-4-" & Year(oDate)) 'Koninginnedag
funWhatSpecialDay = "Koninginnedag"
End Select
End If
End Function
Function funEaster1(ByVal Year As Integer) As Date '1e paasdag
Dim intYear, intMonth, intDay As Integer
Dim g, i, j, c, h, l As Integer
Dim e As Date
g = Year Mod 19
c = Int(Year / 100)
h = (c - Int(c / 4) - Int((8 * c + 13) / 25) + 19 * g + 15) Mod 30
i = h - Int((h / 28)) * (1 - Int((h / 28)) * Int((29 / (h + 1))) * Int(((21 - g) / 11)))
j = (Year + Int(Year / 4) + i + 2 - c + Int(c / 4)) Mod 7
l = i - j
intMonth = 3 + Int((l + 40) / 44)
intDay = l + 28 - 31 * Int((intMonth / 4))
intYear = Year
e = DateSerial(intYear, intMonth, intDay)
While Weekday(e) > 1
e = e + 1
Wend
funEaster1 = e
End Function
Function funEaster2(ByVal intYear As Integer) As Date 'pasen(2e)
funEaster2 = DateSerial(Year(funEaster1(intYear)), Month(funEaster1(intYear)), Day(funEaster1(intYear)) + 1)
End Function
Function funPentecost1(ByVal intYear As Integer) As Date 'pinksteren(1e)
funPentecost1 = DateSerial(intYear, Month(funEaster1(intYear)), Day(funEaster1(intYear)) + 49)
End Function
Function funPentecost2(ByVal intYear As Integer) As Date 'pinksteren(2e)
funPentecost2 = DateSerial(intYear, Month(funEaster1(intYear)), Day(funEaster1(intYear)) + 50)
End Function
Function funAscension(ByVal intYear As Integer) As Date 'hemelvaartsdag
funAscension = DateSerial(Year(funEaster1(intYear)), Month(funEaster1(intYear)), Day(funEaster1(intYear)) + 39)
End Function
Function funGoodFriday(ByVal intYear As Integer) As Date 'Goede vrijdag
funGoodFriday = DateSerial(Year(funEaster1(intYear)), Month(funEaster1(intYear)), Day(funEaster1(intYear)) - 2)
End Function
Function funLenMonth(datDate As Date) As Integer
funLenMonth = DateSerial(Year(datDate), Month(datDate) + 1, 1) - DateSerial(Year(datDate), Month(datDate), 1)
End Function
'////////////////////////////////////////////////////////////////////////////////////////
' Week and Date functions
'////////////////////////////////////////////////////////////////////////////////////////
Function funFirstDayValueOfMonth(ByVal datDate As Date) As Byte
funFirstDayValueOfMonth = Weekday(DateSerial(Year(datDate), Month(datDate), 1), vbMonday)
End Function
Function funConvertWeekNrToBeginDate(ByVal intWeek As Integer, ByVal intYear As Integer) As Date
Dim i As Integer
For i = 1 To 6
If Weekday(DateSerial(intYear, 1, 1 + i), 1) = 1 Then
funConvertWeekNrToBeginDate = DateSerial(intYear, 1, 2 + (i + (intWeek - 1) * 7))
Exit For
End If
Next i
End Function
Function funWeekNr(ByVal datDate As Date) As Integer
funWeekNr = DatePart("ww", datDate, vbMonday, vbFirstFourDays)
End Function