Skip to content

Commit

Permalink
Update Brazil holidays: specify optional holidays (#1452)
Browse files Browse the repository at this point in the history
  • Loading branch information
KJhellico committed Sep 11, 2023
1 parent e841412 commit ce88c1b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
23 changes: 13 additions & 10 deletions holidays/countries/brazil.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from datetime import date

from holidays.calendars.gregorian import JAN, MAR, SEP, NOV, FRI, _get_nth_weekday_from
from holidays.constants import OPTIONAL, PUBLIC
from holidays.groups import ChristianHolidays, InternationalHolidays
from holidays.holiday_base import HolidayBase

Expand Down Expand Up @@ -57,37 +58,37 @@ class Brazil(HolidayBase, ChristianHolidays, InternationalHolidays):
"SP", # São Paulo
"TO", # Tocantins
)
supported_categories = {OPTIONAL, PUBLIC}

def __init__(self, *args, **kwargs) -> None:
ChristianHolidays.__init__(self)
InternationalHolidays.__init__(self)
super().__init__(*args, **kwargs)

def _populate(self, year):
def _populate_public_holidays(self):
# Decreto n. 155-B, de 14.01.1890
if year <= 1889:
if self._year <= 1889:
return None
super()._populate(year)

# New Year's Day.
self._add_new_years_day("Confraternização Universal")

if 1892 <= year <= 1930:
if 1892 <= self._year <= 1930:
# Republic Constitution Day.
self._add_holiday_feb_24("Constituição da Republica")

# Good Friday.
self._add_good_friday("Sexta-feira Santa")

if year not in {1931, 1932}:
if self._year not in {1931, 1932}:
# Tiradentes' Day.
self._add_holiday_apr_21("Tiradentes")

if year >= 1925:
if self._year >= 1925:
# Labor Day.
self._add_labor_day("Dia do Trabalhador")

if year <= 1930:
if self._year <= 1930:
# Discovery of Brazil.
self._add_holiday_may_3("Descobrimento do Brasil")

Expand All @@ -100,7 +101,7 @@ def _populate(self, year):
# Independence Day.
self._add_holiday_sep_7("Independência do Brasil")

if year <= 1930 or year >= 1980:
if self._year <= 1930 or self._year >= 1980:
# Our Lady of Aparecida.
self._add_holiday_oct_12("Nossa Senhora Aparecida")

Expand All @@ -110,11 +111,13 @@ def _populate(self, year):
# Republic Proclamation Day.
self._add_holiday_nov_15("Proclamação da República")

if year >= 1922:
if self._year >= 1922:
# Christmas Day.
self._add_christmas_day("Natal")

# Optional holidays
def _populate_optional_holidays(self):
if self._year <= 1889:
return None

# Carnival.
self._add_carnival_monday("Carnaval")
Expand Down
25 changes: 15 additions & 10 deletions tests/countries/test_brazil.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# Website: https://github.com/dr-prodigy/python-holidays
# License: MIT (see LICENSE file)

from holidays.constants import OPTIONAL, PUBLIC
from holidays.countries.brazil import Brazil, BR, BRA
from tests.common import TestCase

Expand All @@ -22,7 +23,7 @@ def test_country_aliases(self):
self.assertCountryAliases(Brazil, BR, BRA)

def test_no_holidays(self):
self.assertNoHolidays(Brazil(years=1889))
self.assertNoHolidays(Brazil(categories=(OPTIONAL, PUBLIC), years=1889))

def test_new_years_day(self):
self.assertHoliday(f"{year}-01-01" for year in range(1890, 2050))
Expand Down Expand Up @@ -89,8 +90,8 @@ def test_christmas_day(self):
self.assertNoHolidayName("Natal", range(1890, 1922))

def test_optional_holidays(self):
self.assertHolidayName(
"Carnaval",
holidays = Brazil(categories=(OPTIONAL,))
dt = (
"2018-02-12",
"2018-02-13",
"2019-03-04",
Expand All @@ -102,28 +103,32 @@ def test_optional_holidays(self):
"2022-02-28",
"2022-03-01",
)
self.assertHolidayName("Carnaval", holidays, dt)
self.assertNoHoliday(dt)

self.assertHolidayName(
"Início da Quaresma",
dt = (
"2018-02-14",
"2019-03-06",
"2020-02-26",
"2021-02-17",
"2022-03-02",
)
self.assertHolidayName("Início da Quaresma", holidays, dt)
self.assertNoHoliday(dt)

self.assertHolidayName(
"Corpus Christi",
dt = (
"2018-05-31",
"2019-06-20",
"2020-06-11",
"2021-06-03",
"2022-06-16",
)
self.assertHolidayName("Corpus Christi", holidays, dt)
self.assertNoHoliday(dt)

self.assertHoliday(f"{year}-10-28" for year in range(1950, 2050))
self.assertHoliday(f"{year}-12-24" for year in range(1950, 2050))
self.assertHoliday(f"{year}-12-31" for year in range(1950, 2050))
for year in range(1950, 2050):
self.assertHoliday(holidays, f"{year}-10-28", f"{year}-12-24", f"{year}-12-31")
self.assertNoHoliday(f"{year}-10-28", f"{year}-12-24", f"{year}-12-31")

def test_AC_holidays(self):
ac_holidays = Brazil(subdiv="AC", years=range(1995, 2030))
Expand Down

0 comments on commit ce88c1b

Please sign in to comment.