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