vacanza / holidays

Generate and work with holidays in Python
https://pypi.org/project/holidays
MIT License
1.45k stars 460 forks source link

Lacking some holidays on Brazillian calendar #1813

Closed th3worst4 closed 4 months ago

th3worst4 commented 4 months ago

Some holidays as: Corpus Christi, Quarta-feira de Cinzas, Sexta-feira de Carnaval e Páscoa are missing. I believe it's because they're non fixed day holidays.

th3worst4 commented 4 months ago

I've written some code that could fix it:

def get_holidays():
    br_holidays = holidays.country_holidays("BR", years=begin.year)
    for date, holiday in br_holidays.items():
        if holiday == "Sexta-feira Santa":
            easter = date + datetime.timedelta(days=2)

    br_holidays.update({
        easter : "Páscoa",
    })

    i = 0
    while (easter - datetime.timedelta(days=40 + i)).weekday() != 2:
        i+=1

    br_holidays.update({
        easter - datetime.timedelta(days=40 + i) : "Quarta-feira de Cinzas",
        easter - datetime.timedelta(days=40 + i + 5) : "Sexta-feira de Carnaval",
    })

    i = 0
    while(easter + datetime.timedelta(days=60 + i)).weekday() != 3:
        i+=1

    br_holidays.update({
        easter + datetime.timedelta(days=60 + i) : "Corpus Christi"
    })

    return br_holidays

The "Sexta-feira Santa" holiday can be found on the default package dictionary, what I did was just some research on how to calculate the other holidays based on "Páscoa" (Easter) day

th3worst4 commented 4 months ago

The performance of my code may be a crap, but I wanted to create as less variables as possible

KJhellico commented 4 months ago

Hi @th3worst4,

"Corpus Christi" is classified as OPTIONAL holiday in Python Holidays. You can find categories usage examples here.

For "Páscoa" (and rest of holidays), the reasons for their absence are described here. If you have any sources confirming the status of these holidays, please share them with us.