51L3N7

IsHoliday

Oct 17th, 2021 (edited)
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ' Verifica se a data é um feriado (municipal, estadual ou nacional, baseado em Salvador/BA)
  2. ' @author Roger Pestana
  3. ' @date 17/oct/2021
  4. Function IsHoliday(ByVal target_date As String, ByVal reference_year As Integer) As Boolean
  5.         Dim found, holidays_unfixed_index As Integer
  6.         Dim holidays, holiday_carnival, holiday_goodfriday, holiday_corpuschristi As Variant
  7.        
  8.         ' Valores-base
  9.        Const BASE_YEAR = 2021
  10.         Const MAX_HOLIDAYS_YEAR = 2030
  11.         found = False
  12.         holidays_unfixed_index = reference_year Mod BASE_YEAR
  13.  
  14.         ' Lista de feriados definida de 2021 a 2030
  15.        holidays = Array("01/01", "21/04", "01/05", "24/06", "02/07", "07/09", "12/10", "02/11", "15/11", "08/12", "25/12")
  16.         holiday_carnival = Array("16/02/2021", "01/03/2022", "21/02/2023", "13/02/2024", "04/03/2025", "17/02/2026", "09/02/2027", "29/02/2028", "13/02/2029", "05/03/2030")
  17.         holiday_goodfriday = Array("02/04/2021", "15/04/2022", "07/04/2023", "29/04/2024", "18/04/2025", "03/04/2026", "26/03/2027", "14/04/2028", "30/03/2029", "19/04/2030")
  18.         holiday_corpuschristi = Array("03/06/2021", "16/06/2022", "08/06/2023", "30/05/2024", "19/06/2025", "04/06/2026", "27/05/2027", "15/06/2028", "31/05/2029", "20/06/2030")
  19.        
  20.         ' Define os feriados móveis do ano
  21.        If holidays_unfixed_index <= (MAX_HOLIDAYS_YEAR - BASE_YEAR) Then
  22.                 holidays_unfixed_list = Array(holiday_carnival(holidays_unfixed_index), holiday_goodfriday(holidays_unfixed_index), holiday_corpuschristi(holidays_unfixed_index))
  23.         End If
  24.  
  25.         ' Feriados fixos
  26.        For i = 0 To (UBound(holidays) - LBound(holidays))
  27.                 If DateValue(holidays(i) & "/" & reference_year) = DateValue(target_date) Then
  28.                         found = True
  29.                         Exit For
  30.                 End If
  31.         Next i
  32.  
  33.         ' Feriados móveis
  34.        If reference_year >= BASE_YEAR Then
  35.                 If DateValue(holidays_unfixed_list(0)) = DateValue(target_date) _
  36.                         Or DateValue(holidays_unfixed_list(1)) = DateValue(target_date) _
  37.                         Or DateValue(holidays_unfixed_list(2)) = DateValue(target_date) _
  38.                 Then _
  39.                         found = True
  40.         End If
  41.  
  42.         IsHoliday = found
  43. End Function
Add Comment
Please, Sign In to add comment