1*cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?>
2*cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="BankHoliday" script:language="StarBasic">Option Explicit
4*cdf0e10cSrcweir
5*cdf0e10cSrcweirSub Main()
6*cdf0e10cSrcweir	Call CalAutopilotTable()
7*cdf0e10cSrcweirEnd Sub
8*cdf0e10cSrcweir
9*cdf0e10cSrcweir
10*cdf0e10cSrcweirFunction CalEasterTable&amp;(byval Year%)
11*cdf0e10cSrcweirDim B%,C%,D%,E%,F%,G%,H%,I%,K%,L%,M%,N%,O%, nMonth%, nDay%
12*cdf0e10cSrcweir       N = Year% mod 19
13*cdf0e10cSrcweir       B = int(Year% / 100)
14*cdf0e10cSrcweir       C = Year% mod 100
15*cdf0e10cSrcweir       D = int(B / 4)
16*cdf0e10cSrcweir       E = B mod 4
17*cdf0e10cSrcweir       F = int((B + 8) / 25)
18*cdf0e10cSrcweir       G = int((B - F + 1) / 3)
19*cdf0e10cSrcweir       H =(19 * N + B - D - G + 15) mod 30
20*cdf0e10cSrcweir       I = int(C / 4)
21*cdf0e10cSrcweir       K = C mod 4
22*cdf0e10cSrcweir       L =(32 + 2 * E + 2 * I - H - K) mod 7
23*cdf0e10cSrcweir       M = int((N + 11 * H + 22 * L) / 451)
24*cdf0e10cSrcweir       O = H + L - 7 * M + 114
25*cdf0e10cSrcweir       nDay = O mod 31 + 1
26*cdf0e10cSrcweir       nMonth = int(O / 31)
27*cdf0e10cSrcweir	   CalEasterTable&amp; = DateSerial(Year, nMonth,nDay)
28*cdf0e10cSrcweirEnd Function
29*cdf0e10cSrcweir
30*cdf0e10cSrcweir
31*cdf0e10cSrcweir&apos; Note: the following algorithm is valid only till the Year 2100.
32*cdf0e10cSrcweir&apos; but I have no Idea from which date in the paste it is valid
33*cdf0e10cSrcweirFunction CalOrthodoxEasterTable(ByVal iYear as Integer) as Long
34*cdf0e10cSrcweirDim R1%, R2%, R3%, RA%, R4%, RB%, R5%, RC%
35*cdf0e10cSrcweirDim lDate as Long
36*cdf0e10cSrcweir	R1 = iYear mod 19
37*cdf0e10cSrcweir	R2 = iYear mod 4
38*cdf0e10cSrcweir	R3 = iYear mod 7
39*cdf0e10cSrcweir	RA =19 * R1 + 16
40*cdf0e10cSrcweir	R4 = RA mod 30
41*cdf0e10cSrcweir	RB = 2 * R2 + 4 * R3 + 6 * R4
42*cdf0e10cSrcweir	R5 = RB mod 7
43*cdf0e10cSrcweir	RC = R4 + R5
44*cdf0e10cSrcweir	lDate = DateSerial(iYear, 4,4)
45*cdf0e10cSrcweir	CalOrthodoxEasterTable() = lDate + RC
46*cdf0e10cSrcweirEnd Function
47*cdf0e10cSrcweir
48*cdf0e10cSrcweir
49*cdf0e10cSrcweirSub CalInitGlobalVariablesDate()
50*cdf0e10cSrcweirDim i as Integer
51*cdf0e10cSrcweir	For i = 1 To 374
52*cdf0e10cSrcweir		CalBankholidayName$(i) = &quot;&quot;
53*cdf0e10cSrcweir		CalTypeOfBankHoliday%(i) = cHolidayType_None
54*cdf0e10cSrcweir	Next
55*cdf0e10cSrcweirEnd Sub
56*cdf0e10cSrcweir
57*cdf0e10cSrcweir
58*cdf0e10cSrcweirSub CalInsertBankholiday(byval CurDate as Long, byval EventName as String, ByVal iLevel as Integer)
59*cdf0e10cSrcweirDim iDay
60*cdf0e10cSrcweir	iDay =(Month(CurDate)-1)*31 +Day(CurDate)
61*cdf0e10cSrcweir
62*cdf0e10cSrcweir	If 0 &lt;&gt; CalTypeOfBankHoliday(iDay) Then
63*cdf0e10cSrcweir		If iLevel &lt; CalTypeOfBankHoliday(iDay) Then
64*cdf0e10cSrcweir			CalTypeOfBankHoliday(iDay) = iLevel
65*cdf0e10cSrcweir		End If
66*cdf0e10cSrcweir	Else
67*cdf0e10cSrcweir		CalTypeOfBankHoliday(iDay) = iLevel
68*cdf0e10cSrcweir	End If
69*cdf0e10cSrcweir
70*cdf0e10cSrcweir	If CalBankHolidayName(iDay) = &quot;&quot; Then
71*cdf0e10cSrcweir		CalBankHolidayName(iDay) = EventName
72*cdf0e10cSrcweir	Else
73*cdf0e10cSrcweir		CalBankHolidayName(iDay) = CalBankHolidayName(iDay) &amp; &quot; / &quot; &amp; EventName
74*cdf0e10cSrcweir	End If
75*cdf0e10cSrcweirEnd Sub
76*cdf0e10cSrcweir
77*cdf0e10cSrcweirFunction CalMaxDayInMonth(ByVal iYear as Integer, ByVal iMonth as Integer) as Integer
78*cdf0e10cSrcweir&apos; delivers the maximum Day of a month in a certain year
79*cdf0e10cSrcweir	Dim TmpDate as Long
80*cdf0e10cSrcweir	Dim	MaxDay as Long
81*cdf0e10cSrcweir
82*cdf0e10cSrcweir	MaxDay = 28
83*cdf0e10cSrcweir	TmpDate = DateSerial(iYear, iMonth, MaxDay)
84*cdf0e10cSrcweir
85*cdf0e10cSrcweir	While Month(TmpDate) = iMonth
86*cdf0e10cSrcweir		MaxDay = MaxDay + 1
87*cdf0e10cSrcweir		TmpDate = TmpDate + 1
88*cdf0e10cSrcweir	Wend
89*cdf0e10cSrcweir	Maxday = MaxDay - 1
90*cdf0e10cSrcweir	CalMaxDayInMonth() = MaxDay
91*cdf0e10cSrcweirEnd Function
92*cdf0e10cSrcweir
93*cdf0e10cSrcweir
94*cdf0e10cSrcweirFunction CalGetIntOfShortMonthName(ByVal MonthName as String) as Integer
95*cdf0e10cSrcweirDim i as Integer
96*cdf0e10cSrcweirDim nMonth as Integer
97*cdf0e10cSrcweir
98*cdf0e10cSrcweir	nMonth = Val(MonthName)
99*cdf0e10cSrcweir
100*cdf0e10cSrcweir	If (1 &lt;= nMonth And 12 &gt;= nMonth) Then
101*cdf0e10cSrcweir		CalGetIntOfShortMonthName = nMonth
102*cdf0e10cSrcweir		Exit Function
103*cdf0e10cSrcweir	End If
104*cdf0e10cSrcweir
105*cdf0e10cSrcweir	MonthName = UCase(Trim(Left(MonthName, 3)))
106*cdf0e10cSrcweir
107*cdf0e10cSrcweir	For i = 0 To 11
108*cdf0e10cSrcweir		If (UCase(cCalShortMonthNames(i)) = MonthName) Then
109*cdf0e10cSrcweir			CalGetIntOfShortMonthName = i+1
110*cdf0e10cSrcweir			Exit Function
111*cdf0e10cSrcweir		End If
112*cdf0e10cSrcweir	Next
113*cdf0e10cSrcweir
114*cdf0e10cSrcweir	&apos;	Not Found
115*cdf0e10cSrcweir	CalGetIntOfShortMonthName = 0
116*cdf0e10cSrcweirEnd Function
117*cdf0e10cSrcweir
118*cdf0e10cSrcweir
119*cdf0e10cSrcweirSub CalInsertOwnDataInTables(ByVal iSelYear as Integer)
120*cdf0e10cSrcweir	&apos; inserts the individual data from the table into the previously unsorted list
121*cdf0e10cSrcweirDim CurEventName as String
122*cdf0e10cSrcweirDim CurEvMonth as Integer
123*cdf0e10cSrcweirDim CurEvDay as Integer
124*cdf0e10cSrcweirDim LastIndex as Integer
125*cdf0e10cSrcweirDim i as Integer
126*cdf0e10cSrcweirDim DateStr as String
127*cdf0e10cSrcweir	LastIndex = Ubound(DlgCalModel.lstOwnData.StringItemList())
128*cdf0e10cSrcweir	For i = 0 To LastIndex
129*cdf0e10cSrcweir		If GetSelectedDateUnits(CurEvDay, CurEvMonth, i) &lt;&gt; SBDATEUNDEFINED Then
130*cdf0e10cSrcweir			CurEventName = CalGetNameOfEvent(i)
131*cdf0e10cSrcweir			CalInsertBankholiday(DateSerial(iSelYear, CurEvMonth, CurEvDay), CurEventName, cHolidayType_Own)
132*cdf0e10cSrcweir		End If
133*cdf0e10cSrcweir	Next
134*cdf0e10cSrcweirEnd Sub
135*cdf0e10cSrcweir
136*cdf0e10cSrcweir
137*cdf0e10cSrcweir&apos; Finds eg the first,second Monday in a month
138*cdf0e10cSrcweir&apos; Note: in This Function the week starts with the Sunday
139*cdf0e10cSrcweirFunction GetMonthDate(YearInt as Integer, iMonth as Integer, iWeekDay as Integer, iOffset as Integer)
140*cdf0e10cSrcweirDim bFound as Boolean
141*cdf0e10cSrcweirDim lDate as Long
142*cdf0e10cSrcweir	&apos;	1st Tue in Nov : Election Day, Half
143*cdf0e10cSrcweir	bFound = False
144*cdf0e10cSrcweir	lDate = DateSerial(YearInt, iMonth, 1)
145*cdf0e10cSrcweir	Do
146*cdf0e10cSrcweir		If iWeekDay = WeekDay(lDate) Then
147*cdf0e10cSrcweir			bFound = True
148*cdf0e10cSrcweir		Else
149*cdf0e10cSrcweir			lDate = lDate + 1
150*cdf0e10cSrcweir		End If
151*cdf0e10cSrcweir	Loop Until bFound
152*cdf0e10cSrcweir	GetMonthDate = lDate + iOffset
153*cdf0e10cSrcweirEnd Function
154*cdf0e10cSrcweir
155*cdf0e10cSrcweir
156*cdf0e10cSrcweir&apos; Finds the next weekday after a fixed date
157*cdf0e10cSrcweir&apos; e.g. Midsummerfeast in Sweden: next Saturday after 20th June
158*cdf0e10cSrcweirFunction GetNextWeekDay(iYear as Integer, iMonth as Integer, iDay as Integer, iWeekDay as Integer)
159*cdf0e10cSrcweirDim lDate as Long
160*cdf0e10cSrcweirDim iCurWeekDay as Integer
161*cdf0e10cSrcweir	lDate = DateSerial(iYear, iMonth, iDay)
162*cdf0e10cSrcweir	iCurWeekDay = WeekDay(lDate)
163*cdf0e10cSrcweir	While iCurWeekDay &lt;&gt; iWeekDay
164*cdf0e10cSrcweir		lDate = lDate + 1
165*cdf0e10cSrcweir		iCurWeekDay = WeekDay(lDate)
166*cdf0e10cSrcweir	Wend
167*cdf0e10cSrcweir	GetNextWeekDay() = lDate
168*cdf0e10cSrcweirEnd Function
169*cdf0e10cSrcweir
170*cdf0e10cSrcweir
171*cdf0e10cSrcweirSub AddFollowUpHolidays(ByVal lStartDate as Long, iCount as Integer, HolidayName as String, iType as Integer)
172*cdf0e10cSrcweirDim lDate as Long
173*cdf0e10cSrcweir	For lDate = lStartDate + 1 To lStartDate + 4
174*cdf0e10cSrcweir		CalInsertBankholiday(lDate, HolidayName, iType)
175*cdf0e10cSrcweir	Next lDate
176*cdf0e10cSrcweirEnd Sub
177*cdf0e10cSrcweir</script:module>