1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3 <script:module xmlns:
script=
"http://openoffice.org/2000/script" script:
name=
"BankHoliday" script:
language=
"StarBasic">Option Explicit
6 Call CalAutopilotTable()
10 Function CalEasterTable
&(byval Year%)
11 Dim B%,C%,D%,E%,F%,G%,H%,I%,K%,L%,M%,N%,O%, nMonth%, nDay%
18 G = int((B - F +
1) /
3)
19 H =(
19 * N + B - D - G +
15) mod
30
22 L =(
32 +
2 * E +
2 * I - H - K) mod
7
23 M = int((N +
11 * H +
22 * L) /
451)
24 O = H + L -
7 * M +
114
27 CalEasterTable
& = DateSerial(Year, nMonth,nDay)
31 ' Note: the following algorithm is valid only till the Year
2100.
32 ' but I have no Idea from which date in the paste it is valid
33 Function CalOrthodoxEasterTable(ByVal iYear as Integer) as Long
34 Dim R1%, R2%, R3%, RA%, R4%, RB%, R5%, RC%
41 RB =
2 * R2 +
4 * R3 +
6 * R4
44 lDate = DateSerial(iYear,
4,
4)
45 CalOrthodoxEasterTable() = lDate + RC
49 Sub CalInitGlobalVariablesDate()
52 CalBankholidayName$(i) =
""
53 CalTypeOfBankHoliday%(i) = cHolidayType_None
58 Sub CalInsertBankholiday(byval CurDate as Long, byval EventName as String, ByVal iLevel as Integer)
60 iDay =(Month(CurDate)-
1)*
31 +Day(CurDate)
62 If
0 <> CalTypeOfBankHoliday(iDay) Then
63 If iLevel
< CalTypeOfBankHoliday(iDay) Then
64 CalTypeOfBankHoliday(iDay) = iLevel
67 CalTypeOfBankHoliday(iDay) = iLevel
70 If CalBankHolidayName(iDay) =
"" Then
71 CalBankHolidayName(iDay) = EventName
73 CalBankHolidayName(iDay) = CalBankHolidayName(iDay)
& " /
" & EventName
77 Function CalMaxDayInMonth(ByVal iYear as Integer, ByVal iMonth as Integer) as Integer
78 ' delivers the maximum Day of a month in a certain year
83 TmpDate = DateSerial(iYear, iMonth, MaxDay)
85 While Month(TmpDate) = iMonth
90 CalMaxDayInMonth() = MaxDay
94 Function CalGetIntOfShortMonthName(ByVal MonthName as String) as Integer
98 nMonth = Val(MonthName)
100 If (
1 <= nMonth And
12 >= nMonth) Then
101 CalGetIntOfShortMonthName = nMonth
105 MonthName = UCase(Trim(Left(MonthName,
3)))
108 If (UCase(cCalShortMonthNames(i)) = MonthName) Then
109 CalGetIntOfShortMonthName = i+
1
115 CalGetIntOfShortMonthName =
0
119 Sub CalInsertOwnDataInTables(ByVal iSelYear as Integer)
120 ' inserts the individual data from the table into the previously unsorted list
121 Dim CurEventName as String
122 Dim CurEvMonth as Integer
123 Dim CurEvDay as Integer
124 Dim LastIndex as Integer
126 Dim DateStr as String
127 LastIndex = Ubound(DlgCalModel.lstOwnData.StringItemList())
128 For i =
0 To LastIndex
129 If GetSelectedDateUnits(CurEvDay, CurEvMonth, i)
<> SBDATEUNDEFINED Then
130 CurEventName = CalGetNameOfEvent(i)
131 CalInsertBankholiday(DateSerial(iSelYear, CurEvMonth, CurEvDay), CurEventName, cHolidayType_Own)
137 ' Finds eg the first,second Monday in a month
138 ' Note: in This Function the week starts with the Sunday
139 Function GetMonthDate(YearInt as Integer, iMonth as Integer, iWeekDay as Integer, iOffset as Integer)
140 Dim bFound as Boolean
142 ' 1st Tue in Nov : Election Day, Half
144 lDate = DateSerial(YearInt, iMonth,
1)
146 If iWeekDay = WeekDay(lDate) Then
152 GetMonthDate = lDate + iOffset
156 ' Finds the next weekday after a fixed date
157 ' e.g. Midsummerfeast in Sweden: next Saturday after
20th June
158 Function GetNextWeekDay(iYear as Integer, iMonth as Integer, iDay as Integer, iWeekDay as Integer)
160 Dim iCurWeekDay as Integer
161 lDate = DateSerial(iYear, iMonth, iDay)
162 iCurWeekDay = WeekDay(lDate)
163 While iCurWeekDay
<> iWeekDay
165 iCurWeekDay = WeekDay(lDate)
167 GetNextWeekDay() = lDate
171 Sub AddFollowUpHolidays(ByVal lStartDate as Long, iCount as Integer, HolidayName as String, iType as Integer)
173 For lDate = lStartDate +
1 To lStartDate +
4
174 CalInsertBankholiday(lDate, HolidayName, iType)