home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 December / CHIP_CD_2004-12.iso / bonus / oo / OOo_1.1.3_ru_RU_infra_WinIntel_install.exe / $PLUGINSDIR / f_0185 / BankHoliday.xba next >
Extensible Markup Language  |  2004-01-09  |  5KB  |  184 lines

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