Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' Verifica se a data é um feriado (municipal, estadual ou nacional, baseado em Salvador/BA)
- ' @author Roger Pestana
- ' @date 17/oct/2021
- Function IsHoliday(ByVal target_date As String, ByVal reference_year As Integer) As Boolean
- Dim found, holidays_unfixed_index As Integer
- Dim holidays, holiday_carnival, holiday_goodfriday, holiday_corpuschristi As Variant
- ' Valores-base
- Const BASE_YEAR = 2021
- Const MAX_HOLIDAYS_YEAR = 2030
- found = False
- holidays_unfixed_index = reference_year Mod BASE_YEAR
- ' Lista de feriados definida de 2021 a 2030
- holidays = Array("01/01", "21/04", "01/05", "24/06", "02/07", "07/09", "12/10", "02/11", "15/11", "08/12", "25/12")
- 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")
- 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")
- 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")
- ' Define os feriados móveis do ano
- If holidays_unfixed_index <= (MAX_HOLIDAYS_YEAR - BASE_YEAR) Then
- holidays_unfixed_list = Array(holiday_carnival(holidays_unfixed_index), holiday_goodfriday(holidays_unfixed_index), holiday_corpuschristi(holidays_unfixed_index))
- End If
- ' Feriados fixos
- For i = 0 To (UBound(holidays) - LBound(holidays))
- If DateValue(holidays(i) & "/" & reference_year) = DateValue(target_date) Then
- found = True
- Exit For
- End If
- Next i
- ' Feriados móveis
- If reference_year >= BASE_YEAR Then
- If DateValue(holidays_unfixed_list(0)) = DateValue(target_date) _
- Or DateValue(holidays_unfixed_list(1)) = DateValue(target_date) _
- Or DateValue(holidays_unfixed_list(2)) = DateValue(target_date) _
- Then _
- found = True
- End If
- IsHoliday = found
- End Function
Add Comment
Please, Sign In to add comment