Skip to content

Commit

Permalink
Mudanca de nome do arquivo date_utils
Browse files Browse the repository at this point in the history
Para evitar conflito com a nomenclatura date de python
  • Loading branch information
laistdomiciano committed Oct 30, 2024
1 parent 2290389 commit ece9daf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions brutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
from brutils.cpf import (
remove_symbols as remove_symbols_cpf,
)
from brutils.date import (
from brutils.date_utils import (
is_holiday,
)
from brutils.date import (
from brutils.date_utils import (
is_holiday as is_holiday_date,
)

Expand Down
14 changes: 7 additions & 7 deletions brutils/date.py → brutils/date_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import holidays


def is_holiday(date: datetime, uf: str = None) -> Union[bool, None]:
def is_holiday(target_date: datetime, uf: str = None) -> Union[bool, None]:
"""
Checks if the given date is a national or state holiday in Brazil.
Expand All @@ -15,7 +15,7 @@ def is_holiday(date: datetime, uf: str = None) -> Union[bool, None]:
The method does not handle municipal holidays.
Args:
date (datetime): The date to be checked.
target_date (datetime): The date to be checked.
uf (str, optional): The state abbreviation (UF) to check for state holidays.
If not provided, only national holidays will be considered.
Expand All @@ -42,20 +42,20 @@ def is_holiday(date: datetime, uf: str = None) -> Union[bool, None]:
True
"""

if not isinstance(date, datetime):
if not isinstance(target_date, datetime):
return None

valid_ufs = holidays.Brazil().subdivisions
if uf is not None and uf not in valid_ufs:
return None

national_holidays = holidays.Brazil(years=date.year)
national_holidays = holidays.Brazil(years=target_date.year)

if date in national_holidays:
if target_date in national_holidays:
return True

if uf is not None:
state_holidays = holidays.Brazil(prov=uf, years=date.year)
return date in state_holidays
state_holidays = holidays.Brazil(prov=uf, years=target_date.year)
return target_date in state_holidays

return False
2 changes: 1 addition & 1 deletion tests/test_date.py → tests/test_date_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import datetime
from unittest import TestCase

from brutils.date import is_holiday
from brutils.date_utils import is_holiday


class TestIsHoliday(TestCase):
Expand Down

0 comments on commit ece9daf

Please sign in to comment.