Dates and holidays
Brazilian holidays, business days (dias úteis) and dates written out in words.
Add business days
Adds a number of Brazilian business days (dias úteis) to a date. It walks one calendar day at a time and counts only the days date.isBusinessDay accepts with the same options.
- Returns a new date and keeps the time of day. The function never changes the input. When the result day does not have that time (a daylight saving jump), the result is the nearest instant of that day.
- An
amountof 0 returns the same date, even on a non-business day. A negativeamountwalks backwards. options.includeOptional(default true) counts the optional holidays (Carnaval Monday and Tuesday, Corpus Christi) as non-business days. With false, onlynationalandstateholidays count, so Corpus Christi still counts in DF, in MA from 2024 and in RJ from 2026, where it is a state holiday.options.includeSaturday(default false) counts Saturday as a business day, the labor law count of the payroll deadline (CLT art. 459 § 1º, read through IN MTP nº 2/2021, art. 14, I). Sunday and holidays stay excluded, including a holiday on a Saturday (Finados 2024-11-02, Independência 2024-09-07).includeSaturdaydoes not cover municipal holidays, which the IN also excludes. An exact count for a municipality has to remove them separately. The option name does not promise "CLT" for that reason.- A truthy value that is not a boolean (for example
"false") turnsincludeSaturdayorincludeOptionalon. options.stateCodeis read ignoring case and surrounding whitespace, as in every state util:"sp"and" SP "add the holidays of São Paulo. Only an omitted (undefined)stateCodemeans national holidays only.- A
stateCodethat is present and is not a state code ("XX","","__proto__", a number,null, an object) is rejected: the function returnsnullwithout looking at the date. 2.4.0 silently fell back to the national holidays for an unknown or lowercase code, so"sp"counted 9 July as a business day in São Paulo. - Returns
nullfor an invalid date, anamountthat is not a finite integer, or a start or result outside the years 1900 to 2099. - The walk always ends. 2.4.0 could loop forever in time zones where a local day does not exist (Pacific/Apia and Pacific/Fakaofo on 2011-12-30, Pacific/Kiritimati and Pacific/Enderbury on 1994-12-31, Pacific/Kwajalein on 1993-08-21); the walk now skips that day. The half-hour shift of Australia/Lord_Howe was fixed too. Other results are unchanged.
Recipes (no dedicated helper exists):
- Next business day:
addBusinessDays(d, 1). - N-th business day of a month:
addBusinessDays(new Date(y, m, 0), n), starting from the last day of the previous month. Whennis larger than the month's business days, the result falls in the next month; check its month. - Last business day of a month:
subBusinessDays(new Date(y, m + 1, 1), 1), starting from the first day of the next month. - Edges: the n-th business day of January 1900 and the last business day of December 2099 return
null, because the starting day is outside 1900 to 2099. - With
{ includeSaturday: true }the same recipe gives the labor law "quinto dia útil":addBusinessDays(new Date(2024, 2, 0), 5, { includeSaturday: true })is Wednesday 2024-03-06, while the banking count without the option is Thursday 2024-03-07.
| Parameter | Type | Required |
|---|---|---|
date | Date | yes |
amount | number | yes |
options | BusinessDayOptions | no |
options.stateCode | StateCode | no |
options.includeOptional | boolean | no |
options.includeSaturday | boolean | no |
| returns | Date | null |
Add a number of Brazilian business days (dias úteis) to a date, skipping Saturdays, Sundays and the holidays isBusinessDay skips. Signature: addBusinessDays(date, amount, options?), the same as date-fns.
- Options (
BusinessDayOptions, shared withisBusinessDay):includeOptional(defaulttrue) also skips Carnaval Monday and Tuesday and Corpus Christi;includeSaturday(defaultfalse) counts Saturday as a business day;stateCodealso skips that state's holidays. - Returns a new
Date, time of day preserved;dateis never mutated. - An
amountof0returns the same date, even on a weekend or holiday. A negativeamountwalks backwards. - Returns
nullwhendateis invalid,amountis not a finite integer,stateCodeis present and is not a state code, or the result leaves the years 1900 to 2099.
import { addBusinessDays } from '@brazilian-utils/brazilian-utils';
addBusinessDays(new Date(2024, 0, 2, 12), 1); // Date, 2024-01-03 12:00 (next day is already a business day)
addBusinessDays(new Date(2024, 11, 31, 12), 1); // Date, 2025-01-02 12:00 (2025-01-01 is Ano novo, skipped)
addBusinessDays(new Date(2024, 0, 5, 12), -1); // Date, 2024-01-04 12:00 (walks backwards)
addBusinessDays(new Date(2024, 0, 6, 12), 0); // Date, 2024-01-06 12:00 (unchanged, even though Saturday is not a business day)
addBusinessDays(new Date(2024, 0, 5, 12), 1, { includeSaturday: true }); // Date, 2024-01-06 12:00 (labour law count, Saturday counts)
addBusinessDays(new Date(2024, 10, 1, 12), 1, { includeSaturday: true }); // Date, 2024-11-04 12:00 (2024-11-02 is Finados, a holiday on a Saturday)
addBusinessDays(new Date(2024, 6, 8, 12), 1, { stateCode: 'SP' }); // Date, 2024-07-10 12:00 (2024-07-09 is Revolução Constitucionalista in SP, skipped)
addBusinessDays(new Date('not a date'), 1); // null
addBusinessDays(new Date(2024, 0, 2), 1.5); // null (not an integer)Try it with JavaScript addBusinessDays
Shared test cases (0) and the result in each library date.addBusinessDays
This function has no shared test cases yet.
Write out in words
- JavaScript library
- Python library32 cases fail
- Go library2 cases fail
- Ruby library4 cases fail
- Rust library
- .NET library1 case fails
- Erlang library
Writes a date in Brazilian Portuguese words ("por extenso"), such as "primeiro de janeiro de dois mil e vinte e quatro".
valueis a date (its local calendar date) or a stringdd/mm/yyyyor ISOyyyy-mm-dd.options.style(default"full") spells out the day, the month and the year ("dois de março de dois mil e vinte e quatro")."month"spells out only the month and leaves the day and the year as digits ("2 de março de 2024"), with day 1 as1º("1º de janeiro de 2024"). Any other value is ignored and"full"is used.options.weekday(default false) puts the weekday name in lowercase and a comma in front ("sábado, dois de março de dois mil e vinte e quatro"). The weekday comes from the resolved calendar date: the local date of a date value, or the parsed date of a string. It combines with either style.styleandweekdayare read strictly: only"month"and onlytruechange the output."true"or1forweekdaydo nothing.- Day 1 is "primeiro" in the
fullstyle. - In the
fullstyle the year is written asnumber.convertToWordswrites it (1999is "mil novecentos e noventa e nove",2000is "dois mil"). The result is always lowercase. - February 29th is accepted only on leap years of the proleptic Gregorian calendar (divisible by 4, except centuries not divisible by 400). A string must match
dd/mm/yyyyoryyyy-mm-ddexactly, with no other characters around it.
Pending decision
The reference (JS) writes all lowercase and parses ISO strings. Go and Ruby capitalize and do not parse ISO strings. See the open decision in docs/findings.md.
Pending decision
The reference (JS) returns an empty string for an invalid date, a malformed string, a day or month that does not exist, or a year before 1. Other libraries return null. See the open decision in docs/findings.md.
| Parameter | Type | Required |
|---|---|---|
value | Date | string | yes |
options | ConvertDateToWordsOptions | no |
options.style | "full" | "month" | no |
options.weekday | boolean | no |
| returns | string |
Write a date in Brazilian Portuguese words ("por extenso"): "01/01/2024" becomes "primeiro de janeiro de dois mil e vinte e quatro". Accepts a Date, read by its local calendar date, or a string in "dd/mm/yyyy" or ISO "yyyy-mm-dd" format.
- Options (
ConvertDateToWordsOptions):style(default"full") spells out day, month and year;"month"spells out only the month and leaves day and year as digits, day 1 as"1º".weekday(defaultfalse) prefixes the lowercase weekday name and a comma. - Returns
""for an invalidDate, a malformed string, a day or month that does not exist, or a date before year 1.
import { convertDateToWords } from '@brazilian-utils/brazilian-utils';
convertDateToWords('01/01/2024'); // "primeiro de janeiro de dois mil e vinte e quatro"
convertDateToWords('2024-01-02'); // "dois de janeiro de dois mil e vinte e quatro"
convertDateToWords(new Date(2024, 0, 1)); // "primeiro de janeiro de dois mil e vinte e quatro"
convertDateToWords('02/03/2024', { style: 'month' }); // "2 de março de 2024"
convertDateToWords('01/01/2024', { style: 'month' }); // "1º de janeiro de 2024"
convertDateToWords('02/03/2024', { weekday: true }); // "sábado, dois de março de dois mil e vinte e quatro"
convertDateToWords('10/05/1999'); // "dez de maio de mil novecentos e noventa e nove"
convertDateToWords('31/04/2024'); // "" (April has 30 days)
convertDateToWords('invalid'); // ""
convertDateToWords('29/02/1900'); // "" (1900 is not a leap year)Try it with JavaScript convertDateToWords
Shared test cases (37) and the result in each library date.convertToWords
Difference in business days
Counts the Brazilian business days between two dates.
- Counts
earlierDatewhen it is a business day, and every business day strictly between the two. It never countslaterDate. The time of day is ignored. - The result is negative when
laterDateis beforeearlierDate, and 0 on the same calendar day. optionsas indate.addBusinessDays:includeOptional,includeSaturdayandstateCode. With{ includeSaturday: true }, 2024-01-01 to 2024-01-08 gives 5 (1 January is a holiday, Sunday is excluded).- Returns
nullwhen either date is invalid or outside the years 1900 to 2099, and whenoptions.stateCodeis present and is not a state code (2.4.0 fell back to national holidays).
| Parameter | Type | Required |
|---|---|---|
laterDate | Date | yes |
earlierDate | Date | yes |
options | BusinessDayOptions | no |
options.stateCode | StateCode | no |
options.includeOptional | boolean | no |
options.includeSaturday | boolean | no |
| returns | number | null |
Count the Brazilian business days (dias úteis) between two dates. Signature: differenceInBusinessDays(laterDate, earlierDate, options?), the same as date-fns.
- Options (
BusinessDayOptions, shared withisBusinessDay):includeOptional(defaulttrue) also skips Carnaval Monday and Tuesday and Corpus Christi;includeSaturday(defaultfalse) counts Saturday as a business day;stateCodealso skips that state's holidays. - Counts
earlierDatewhen it is a business day and every business day strictly between the two dates;laterDateis never counted. The time of day is ignored. - The result is negative when
laterDateis beforeearlierDate, and0on the same calendar day. - Returns
nullwhen either date is not a validDateor is outside the years 1900 to 2099, orstateCodeis present and is not a state code.
import { differenceInBusinessDays } from '@brazilian-utils/brazilian-utils';
differenceInBusinessDays(new Date(2024, 0, 2), new Date(2024, 0, 1)); // 0 (Jan 1 is Ano novo, not counted)
differenceInBusinessDays(new Date(2024, 0, 3), new Date(2024, 0, 2)); // 1 (Jan 2 counted, a Tuesday; Jan 3 is not)
differenceInBusinessDays(new Date(2024, 0, 2), new Date(2024, 0, 3)); // -1 (the later date comes first, so the count is negative)
differenceInBusinessDays(new Date(2024, 0, 2), new Date(2024, 0, 2)); // 0 (same day)
differenceInBusinessDays(new Date(2024, 0, 8), new Date(2024, 0, 1)); // 4 (Monday to Friday count, 2024-01-02 to 2024-01-05)
differenceInBusinessDays(new Date(2024, 0, 8), new Date(2024, 0, 1), { includeSaturday: true }); // 5 (2024-01-06, a Saturday, also counts)
differenceInBusinessDays(new Date(2024, 10, 4), new Date(2024, 10, 1), { includeSaturday: true }); // 1 (2024-11-02 is Finados, a holiday on a Saturday)
differenceInBusinessDays(new Date(2024, 6, 10), new Date(2024, 6, 8), { stateCode: 'SP' }); // 1 (2024-07-09 is a state holiday in SP)
differenceInBusinessDays(new Date(), new Date('not a date')); // nullTry it with JavaScript differenceInBusinessDays
Shared test cases (0) and the result in each library date.differenceInBusinessDays
This function has no shared test cases yet.
Get holidays
- JavaScript library
- Python library
- Go library8 cases fail
- Ruby library
- Rust library
- .NET library8 cases fail
- Erlang library
Returns the Brazilian holidays of a year, sorted by date: the national ones, plus those of one state when stateCode is given.
optionsis{ year, stateCode? }. JavaScript also accepts a bare year,getHolidays(2024), for the national holidays.- Each holiday has a name, a date and a
type:national,state,optional(ponto facultativo) orreligious(Páscoa, listed for convenience; no norm declares it). stateCodeis read ignoring case and surrounding whitespace, as in every state util. Only an omitted (undefined)stateCodemeans national holidays only.- A
stateCodethat is present and is not a state code ("XX","","__proto__", a number,null, an object) returns an empty list. 2.4.0 returned the national holidays for it, so{ year: 2024, stateCode: "sp" }left out the São Paulo holidays. - Returns an empty list when
yearis not an integer from 1900 to 2099. - Each holiday appears only in the years its norm was in force:
- Fixed national holidays appear only in the years a federal norm declared them. Finados appears up to 1948 and from 2003 on, not from 1949 to 2002 (2.4.0 listed it every year). Nossa Senhora Aparecida appears from 1980. Dia da Consciência Negra (20 November) is national from 2024.
- Natal appears from 1922, Dia do trabalhador from 1925, and Tiradentes up to 1930, from 1933 to 1948 and from 1951. Lei nº 662/1949 left Finados out of the national holidays Decreto-lei nº 486/1938 listed, and Lei nº 10.607/2002 put it back. The other national festivals of the first republican calendar (24 February, 3 May, 13 May, 14 July and 12 October) are listed up to 1930, and 3 May (1936 to 1938), 16 July and 12 October (1936 and 1937) again under Lei nº 108/1935.
- State holidays appear from the year their law took effect, and up to the year it was revoked.
- Sexta-feira Santa is
nationalevery year. Carnaval Monday and Tuesday and Corpus Christi areoptional, the pontos facultativos of the federal calendar (2.4.0 did not list the Monday). - The
optionalentries are the whole-day pontos facultativos of the federal calendar (Portarias MGI nº 8.617/2023, 9.783/2024 and 11.460/2025, for 2024 to 2026): Carnaval Monday and Tuesday and Corpus Christi, the same three days the financial market skips (Resolução CMN nº 4.880/2020), plus the ones a state norm declares (AM's 8 December from 1999, PE's 6 March of 2008 and 2009). The partial ones are left out: Quarta-feira de Cinzas (until 14h), 28 October (Dia do Servidor Público) and the afternoons of 24 and 31 December. - The first round of the elections is a
nationalholiday: the first Sunday of October in even years from 1998 on (15 November in 2020), under art. 380 of the Código Eleitoral. The second round is not listed. - Before 1998, Lei nº 1.266/1950 made the day of the general elections a national holiday, so the ones held on a weekday are listed too: 3 October of 1955 and 1958 (
Eleições gerais) and of 1990 and 1994 (Eleições (primeiro turno)). 3 October 1960 and the municipal election of 3 October 1996 are not listed. Being a Sunday, the election day never changes a business day count. - A state entry with the same name and date as a national one replaces it. Corpus Christi is typed
statein DF, in MA from 2024 and in RJ from 2026, and stays an optional federal ponto facultativo elsewhere. The Carnaval Tuesday is a state holiday in RJ from 2009. - Two observance shifts move a state date. Alagoas' 30 November goes back to Monday when it falls on a Tuesday and on to Friday when it falls on a Thursday (from 2014, Lei AL nº 7.530/2013). Santa Catarina's 11 August (from 2005) and 25 November (from 1999) each move to the following Sunday when they fall Monday to Saturday. Pernambuco's data magna falls on the first Sunday of March from 2010 to 2017 and on 6 March from 2018.
- A state law the STF struck down has no entry in any year: Rondônia's 18 June (ADI 3940) and Amapá's 25 July (ADI 4820).
- Goiás lists 26/07, 24/10 and 28/10 as the feriados estaduais of the state servants' statute, from 1986, and 2 November as a Goiás holiday from 1986 to 2002, the years Finados was not national. Alagoas' 16/09 is a
stateholiday from 2011 (2.4.0 typed itoptionalup to 2023). - Changes in 2.5.0, each from the state norm cited in the JavaScript source:
- RJ: Corpus Christi from 2026 (Lei RJ nº 11.002/2025, upheld by the STF in ADI 7898, final on 13/08/2026). 2.4.0 typed it
optional, as in every other state. - AL: 20/11 from 1995 to 2023; 30/11 from 2014 (moved to Monday when it falls on a Tuesday and to Friday when it falls on a Thursday).
- AC: 20/01 from 2017. AP: 20/11 from 2008 to 2023; 15/05 from 2018. AP's 25/07 has no entry in any year (see below).
- MA: Corpus Christi from 2024; 08/03 from 2027. PB: 05/08 from 1968.
- SE: 08/07 from 1990; 24/10 from 1989 to 1999. PR: 19/12 from 1963 to 2013 (Lei PR 4.658/1962, revoked by Lei PR 18.384/2014).
- PE: 06/03 in 2008 and 2009 as
optional(Lei PE 13.386/2007). AM: 08/12 asoptionalfrom 1999 (the state declares it a ponto facultativo in its offices by decree, DOE-AM of 02/12/2025; the earliest norm located is Lei Municipal de Manaus nº 496/1999). 2.4.0 listed it from 1900.
- RJ: Corpus Christi from 2026 (Lei RJ nº 11.002/2025, upheld by the STF in ADI 7898, final on 13/08/2026). 2.4.0 typed it
- Returns an empty list when the argument is neither a number nor an object.
- Municipal holidays are not covered.
- One-year moves made by decree are not applied; the table keeps the statutory date. Examples: Decreto GO nº 10.935/2026 moved 26/07/2026 to 20/07, and Goiás moved 28/10/2026 to 30/10.
- Also not applied: Acre's law that moves the holidays falling Tuesday to Thursday to the Friday (Lei AC nº 2.126/2009), because the state's own yearly decrees apply it unevenly (2026 moves 20/01 and leaves 17/11, a Tuesday, in place).
| Parameter | Type | Required |
|---|---|---|
options | GetHolidaysParams | yes |
options.year | number | yes |
options.stateCode | StateCode | no |
| returns | Holiday[] |
Get the Brazilian holidays of a year: the national ones and, with a stateCode, that state's holidays too. Accepts a year or { year, stateCode } (GetHolidaysParams).
- Each holiday is a
Holidaywhosetype(HolidayType) is"national","state","optional"or"religious". Holidays are sorted by date. - "Dia da Consciência Negra", Nov 20, is national from 2024 on.
- The first round of the elections, "Eleições (primeiro turno)", is a national holiday in the even years from 1998 on (Código Eleitoral, art. 380): the first Sunday of October, or Nov 15 in 2020 (EC nº 107/2020). The second round is left out, since it is held only where one is needed. Being a Sunday, it never changes a business day count. Before 1998, Lei nº 1.266/1950 made the day of the general elections a national holiday, so the ones held on a weekday are listed too: Oct 3 of 1955 and 1958 ("Eleições gerais") and of 1990 and 1994 ("Eleições (primeiro turno)"). Oct 3, 1960 is left out, since no official text found dates that year's presidential election, and so is the municipal election of Oct 3, 1996.
- Each fixed-date national holiday is listed only for the years a federal norm declared it (Sexta-feira Santa, which the federal calendar portarias list as a feriado nacional every year, is listed every year): Nossa Senhora Aparecida from 1980, Natal from 1922, Dia do trabalhador from 1925, Tiradentes up to 1930, from 1933 to 1948 and from 1951, and Finados up to 1948 and from 2003. Lei nº 662/1949 left Finados out of the feriados nacionais that Decreto-lei nº 486/1938 listed, and only Lei nº 10.607/2002 put it back (the Câmara report on its bill: "Só inova ao sugerir o dia de finados"); up to 2.4.0 it was listed every year. The other "festas nacionais" of the first republican calendar (Decreto nº 155-B/1890 and Decreto nº 3/1891: Feb 24, May 3, May 13, Jul 14 and Oct 12) are listed up to 1930, and May 3 (1936 to 1938), Jul 16 and Oct 12 (1936 and 1937) again under Lei nº 108/1935.
- The
"optional"entries are the whole-day pontos facultativos of the federal calendar (Portarias MGI nº 8.617/2023, 9.783/2024 and 11.460/2025, for 2024 to 2026, all of which list both Carnaval days as ponto facultativo, never as feriado nacional): Carnaval Monday and Tuesday and Corpus Christi, the same three days the financial market skips (Resolução CMN nº 4.880/2020), plus the state ones a state norm declares (AM's Dec 8 from 1999, which the state declares for its offices by decree, and PE's Mar 6 in 2008 and 2009).includeOptionalswitches exactly these. The partial ones are left out: Quarta-feira de Cinzas (until 14h), Oct 28 (Dia do Servidor Público) and the Dec 24 and Dec 31 afternoons. - Per-state rules (SC's Sunday shift of a date falling Monday to Saturday, as Decreto SC nº 1.460/2018 did with a Saturday Aug 11; PE's data magna on the first Sunday of March from 2010 to 2017; AL's Nov 30 moved to Monday from a Tuesday and to Friday from a Thursday, DF's, MA's (from 2024) and RJ's (from 2026) Corpus Christi and RJ's Carnaval Tuesday typed
"state", dates that stopped being holidays) follow each state's law; see the source for the list. AL's Sep 16 is a state holiday from 2011, as the state's calendar decrees label it before Lei AL nº 9.358/2024. A state law the STF struck down has no entry in any year: RO's Jun 18 (ADI 3940) and AP's Jul 25 (ADI 4820). - Other shifts are not applied and the statutory date is returned: AC's law moves the feriados falling Tuesday to Thursday to the Friday (Lei AC nº 2.126/2009), but the state's own yearly decrees apply it unevenly (2026 moves Jan 20 and leaves Nov 17, a Tuesday, in place).
- GO's three dates (Jul 26, Oct 24, Oct 28) are the "feriados estaduais" of the state servants' statute, listed from 1986 (Lei GO nº 9.990/1986, then Lei GO nº 10.460/1988 and Lei GO nº 20.756/2020, art. 269, II); the same statutes made Nov 2 a GO holiday from 1986 to 2002, the years it was not a national one. No Goiás law fixing a data magna as a civil holiday was found. The governor moves Jul 26 by decree every year (2025: Jul 28; 2026: Jul 20), and Oct 28 most years (2025: Oct 27; 2026: Oct 30), so the statutory date returned here is often not the day observed.
- Each state holiday is listed only from the first year its state law applied (SP's Jul 9 from 1997, RJ's São Jorge from 2008, SC's Aug 11 from 2004), so an older year has fewer state holidays.
stateCodeignores letter case and surrounding whitespace ('sp'is'SP'). Only an omitted (orundefined)stateCodeasks for the national holidays alone: any other value that is not a state code ('XX','', a value that is not a string) returns[]. Up to 2.4.0 an unknown code was ignored and the national holidays were returned, so a typo such as'sp'silently dropped the state's holidays.- Returns
[]when the year is not an integer from 1900 to 2099, or when the argument is neither a number nor an object.
import { getHolidays } from '@brazilian-utils/brazilian-utils';
// Get the holidays of 2024, national and optional ones
getHolidays(2024);
// [
// { name: 'Ano novo', date: Date('2024-01-01'), type: 'national' },
// { name: 'Carnaval (segunda-feira)', date: Date('2024-02-12'), type: 'optional' },
// { name: 'Carnaval (terça-feira)', date: Date('2024-02-13'), type: 'optional' },
// { name: 'Sexta-feira Santa', date: Date('2024-03-29'), type: 'national' },
// { name: 'Páscoa', date: Date('2024-03-31'), type: 'religious' },
// { name: 'Tiradentes', date: Date('2024-04-21'), type: 'national' },
// { name: 'Dia do trabalhador', date: Date('2024-05-01'), type: 'national' },
// { name: 'Corpus Christi', date: Date('2024-05-30'), type: 'optional' },
// { name: 'Independência do Brasil', date: Date('2024-09-07'), type: 'national' },
// { name: 'Eleições (primeiro turno)', date: Date('2024-10-06'), type: 'national' },
// { name: 'Nossa Senhora Aparecida', date: Date('2024-10-12'), type: 'national' },
// { name: 'Finados', date: Date('2024-11-02'), type: 'national' },
// { name: 'Proclamação da República', date: Date('2024-11-15'), type: 'national' },
// { name: 'Dia da Consciência Negra', date: Date('2024-11-20'), type: 'national' },
// { name: 'Natal', date: Date('2024-12-25'), type: 'national' },
// ]
// Get holidays for a specific state
getHolidays({ year: 2024, stateCode: 'SP' });
// Includes national holidays plus state-specific holidays (e.g., "Revolução Constitucionalista")Source: src/get-holidays/constants.ts, Lei nº 662/1949, Lei nº 9.093/1995.
Try it with JavaScript getHolidays
Shared test cases (14) and the result in each library date.getHolidays
Is business day
Checks whether a date is a Brazilian business day (dia útil), by its local calendar date. A business day is not a Saturday, a Sunday or a holiday of date.getHolidays for the same state.
options.includeOptional(default true) counts the optional holidays (Carnaval Monday and Tuesday, Corpus Christi, and theoptionalentries a state has, AM's 8 December and PE's 6 March of 2008 and 2009) as non-business days. With false, onlynationalandstateholidays count, so Corpus Christi still counts in DF, in MA from 2024 and in RJ from 2026, where it is a state holiday.options.includeSaturday(default false) counts Saturday as a business day, the labor law count of the payroll deadline (CLT art. 459 § 1º, read through IN MTP nº 2/2021, art. 14, I). Sunday and holidays stay excluded, including a holiday on a Saturday (Finados 2024-11-02, Independência 2024-09-07).includeSaturdaydoes not cover municipal holidays, which the IN also excludes. An exact count for a municipality has to remove them separately. The option name does not promise "CLT" for that reason.- A truthy value that is not a boolean (for example
"false") turnsincludeSaturdayorincludeOptionalon. - An
optionsthat is not an object is ignored, as if it were omitted. options.stateCodeis read ignoring case and surrounding whitespace, as in every state util:"sp"and" SP "add the holidays of São Paulo. Only an omitted (undefined)stateCodemeans national holidays only.- A
stateCodethat is present and is not a state code ("XX","","__proto__", a number,null, an object) is rejected: the function returnsfalsewithout looking at the date. 2.4.0 silently fell back to the national holidays for an unknown or lowercase code, so"sp"counted 9 July as a business day in São Paulo. - This is not by itself a bank or court calendar: banks also close on their branch's local holidays, and courts follow their own calendars.
- Returns false for an invalid date or a year outside 1900 to 2099.
| Parameter | Type | Required |
|---|---|---|
value | Date | yes |
options | BusinessDayOptions | no |
options.stateCode | StateCode | no |
options.includeOptional | boolean | no |
options.includeSaturday | boolean | no |
| returns | boolean |
Check if a date is a Brazilian business day (dia útil): not a Saturday, a Sunday or a holiday getHolidays lists for its local calendar day.
- Options (
BusinessDayOptions, shared by every business day util):includeOptional(defaulttrue) also counts the"optional"holidays, Carnaval Monday and Tuesday and Corpus Christi, as non-business days;includeSaturday(defaultfalse) counts Saturday as a business day;stateCodealso counts that state's holidays. includeSaturdayoff is a Monday to Friday count. It is not by itself the calendar of banks or courts: the financial market also skips Carnaval Monday and Tuesday and Corpus Christi (Resolução CMN nº 4.880/2020, art. 6º), which the defaultincludeOptionalcovers, and banks close on local holidays; the federal courts also close from Dec 20 to Jan 6, from Holy Wednesday to Easter, on Carnaval Monday and Tuesday, Aug 11, Nov 1 and 2 and Dec 8 (Lei nº 5.010/1966, art. 62), and procedural deadlines follow each court's calendar (CPC art. 216). On, it is the labour law count of the payroll deadline of CLT art. 459 § 1º, the one labour inspection reads through Instrução Normativa MTP nº 2/2021, art. 14, I: "na contagem dos dias será incluído o sábado, excluindo-se o domingo e o feriado, inclusive o municipal".- Sunday and holidays are still excluded with
includeSaturdayon, so a holiday that falls on a Saturday is still not a business day. - The "inclusive o municipal" part of that rule is not covered:
getHolidayscarries national and state holidays only, so a municipal holiday counts here as an ordinary business day. Remove the municipal holidays yourself when a count has to be exact for one municipality. - Returns
falsewhenvalueis not a validDateor its year is outside 1900 to 2099, or whenstateCodeis present and is not a state code ('XX','', a value that is not a string). Letter case and surrounding whitespace instateCodeare ignored.
import { isBusinessDay } from '@brazilian-utils/brazilian-utils';
isBusinessDay(new Date(2024, 0, 2)); // true (Tuesday, not a holiday)
isBusinessDay(new Date(2024, 0, 1)); // false (Ano novo)
isBusinessDay(new Date(2024, 0, 6)); // false (Saturday)
isBusinessDay(new Date(2024, 0, 6), { includeSaturday: true }); // true (labour law count)
isBusinessDay(new Date(2024, 8, 7), { includeSaturday: true }); // false (Independência, a holiday on a Saturday)
isBusinessDay(new Date(2024, 0, 7), { includeSaturday: true }); // false (Sunday is never included)
isBusinessDay(new Date(2024, 1, 12)); // false (Carnaval Monday, optional holiday, counts by default)
isBusinessDay(new Date(2024, 1, 13)); // false (Carnaval Tuesday, optional holiday, counts by default)
isBusinessDay(new Date(2024, 1, 13), { includeOptional: false }); // true
isBusinessDay(new Date(2024, 6, 9), { stateCode: 'SP' }); // false (Revolução Constitucionalista)
isBusinessDay(new Date(2024, 6, 9)); // true (state holiday ignored without stateCode)
isBusinessDay(new Date('not a date')); // falseTry it with JavaScript isBusinessDay
Shared test cases (0) and the result in each library date.isBusinessDay
This function has no shared test cases yet.
Is holiday
Checks whether a date is a Brazilian holiday, by its local calendar date.
optionscarries the target date and, optionally, a state code whose holidays also count. Every holidaydate.getHolidayslists counts, optional ones and the first round of the elections included.options.stateCodeis read ignoring case and surrounding whitespace, as in every state util:"sp"and" SP "add the holidays of São Paulo. Only an omitted (undefined)stateCodemeans national holidays only.- A
stateCodethat is present and is not a state code ("XX","","__proto__", a number,null, an object) is rejected: the function returnsfalsewithout looking at the date. 2.4.0 silently fell back to the national holidays for an unknown or lowercase code, so"sp"did not find 9 July as a holiday in São Paulo. options.targetDateis the date to check. It is read by its local calendar day, not by its UTC instant.options.stateCodeis optional.- Returns false when
targetDateis missing or is not a valid date, and whenstateCodeis present and is not a state code, even on a national holiday. - Returns false for a year outside 1900 to 2099, where
date.getHolidayslists nothing. - The
optionalandreligiousentries ofdate.getHolidayscount: Carnaval Monday and Tuesday, Corpus Christi and Páscoa make the function returntrue. There is noincludeOptionalhere, unlikedate.isBusinessDay.
| Parameter | Type | Required |
|---|---|---|
options | IsHolidayParams | no |
options.targetDate | Date | no |
options.stateCode | StateCode | no |
| returns | boolean |
Check if a date is a Brazilian holiday. Accepts { targetDate, stateCode? } (IsHolidayParams).
- The check uses
targetDate's local calendar date, not its UTC instant. stateCodealso considers that state's holidays, read as ingetHolidays(letter case and surrounding whitespace are ignored).- Returns
falsewhentargetDateis missing or not a validDate, or whenstateCodeis present and is not a state code ('XX','', a value that is not a string), even on a national holiday. - Returns
falsefor a year outside 1900 to 2099, wheregetHolidayslists nothing. - The
"optional"and"religious"entries ofgetHolidayscount: Carnaval Monday and Tuesday, Corpus Christi and Páscoa makeisHolidaytrue. There is noincludeOptionalhere, unlikeisBusinessDay.
import { isHoliday } from '@brazilian-utils/brazilian-utils';
isHoliday({ targetDate: new Date(2024, 0, 1) }); // true
isHoliday({ targetDate: new Date(2024, 6, 9), stateCode: 'SP' }); // true
isHoliday(); // falseTry it with JavaScript isHoliday
Shared test cases (5) and the result in each library date.isHoliday
Sub business days
Subtracts a number of Brazilian business days from a date. This is the same as date.addBusinessDays with the opposite amount.
- Same rules and options as
date.addBusinessDays(includeOptional,includeSaturday,stateCode), including the same caveat on the time of day. A negativeamountwalks forwards. - Last business day of a month:
subBusinessDays(new Date(y, m + 1, 1), 1). For December 2099 this returnsnull, because the starting day is in 2100.
| Parameter | Type | Required |
|---|---|---|
date | Date | yes |
amount | number | yes |
options | BusinessDayOptions | no |
options.stateCode | StateCode | no |
options.includeOptional | boolean | no |
options.includeSaturday | boolean | no |
| returns | Date | null |
Subtract a number of Brazilian business days (dias úteis) from a date. subBusinessDays(date, amount, options?) is addBusinessDays(date, -amount, options).
- Same rules as
addBusinessDays,BusinessDayOptionsincluded. A negativeamountwalks forwards.
import { subBusinessDays } from '@brazilian-utils/brazilian-utils';
subBusinessDays(new Date(2024, 0, 5, 12), 1); // Date, 2024-01-04 12:00 (previous day is already a business day)
subBusinessDays(new Date(2024, 0, 8, 12), 1); // Date, 2024-01-05 12:00 (walks back over the weekend)
subBusinessDays(new Date(2025, 0, 2, 12), 1); // Date, 2024-12-31 12:00 (2025-01-01 is Ano novo, skipped)
subBusinessDays(new Date(2024, 0, 5, 12), -1); // Date, 2024-01-08 12:00 (walks forwards)
subBusinessDays(new Date(2024, 0, 6, 12), 0); // Date, 2024-01-06 12:00 (unchanged, even though Saturday is not a business day)
subBusinessDays(new Date(2024, 0, 8, 12), 1, { includeSaturday: true }); // Date, 2024-01-06 12:00 (labour law count, Saturday counts)
subBusinessDays(new Date(2024, 10, 4, 12), 1, { includeSaturday: true }); // Date, 2024-11-01 12:00 (2024-11-02 is Finados, a holiday on a Saturday)
subBusinessDays(new Date(2024, 6, 10, 12), 1, { stateCode: 'SP' }); // Date, 2024-07-08 12:00 (2024-07-09 is Revolução Constitucionalista in SP, skipped)
subBusinessDays(new Date('not a date'), 1); // null
subBusinessDays(new Date(2024, 0, 2), 1.5); // null (not an integer)To get the n-th business day of a month, or the last one, start from the day just outside the month:
import { addBusinessDays, subBusinessDays } from '@brazilian-utils/brazilian-utils';
// n-th business day of the month: add n from the last day of the month before
addBusinessDays(new Date(2024, 0, 0), 5); // Date, 2024-01-08 00:00 (5th business day of January 2024)
addBusinessDays(new Date(2024, 1, 0), 10); // Date, 2024-02-16 00:00 (10th of February 2024, Carnaval Monday and Tuesday skipped)
// last business day of the month: subtract 1 from the first day of the month after
subBusinessDays(new Date(2024, 3, 1), 1); // Date, 2024-03-28 00:00 (2024-03-29 is Sexta-feira Santa, then a weekend)
subBusinessDays(new Date(2024, 1, 1), 2); // Date, 2024-01-30 00:00 (2nd to last of January 2024)
// payroll deadline of CLT art. 459 § 1º: the 5th business day in the labour law count
addBusinessDays(new Date(2024, 2, 0), 5, { includeSaturday: true }); // Date, 2024-03-06 00:00 (2024-03-02, a Saturday, counts; the Monday to Friday count gives 2024-03-07)
addBusinessDays(new Date(2024, 10, 0), 5, { includeSaturday: true }); // Date, 2024-11-07 00:00 (2024-11-02 is Finados, a holiday on a Saturday)
subBusinessDays(new Date(2024, 8, 1), 1, { includeSaturday: true }); // Date, 2024-08-31 00:00 (last business day of August 2024, a Saturday)- An
nbeyond the business days of the month lands in the next month (addBusinessDays(new Date(2024, 0, 0), 23)is 2024-02-01, January 2024 has 22); comparegetMonth()when that matters. - The payroll "quinto dia útil" of CLT art. 459 § 1º is the labour law count: pass
{ includeSaturday: true }. Municipal holidays, which that count also excludes, are not known to the library, so a municipal holiday early in the month still has to be accounted for by the caller. - The n-th business day of January 1900 and the last business day of December 2099 return
null, since the recipe starts from a day outside the supported years (31 December 1899 and 1 January 2100).
Try it with JavaScript subBusinessDays
Shared test cases (0) and the result in each library date.subBusinessDays
This function has no shared test cases yet.
Official sources
- planalto.gov.br/ccivil_03/decreto-lei/…/del5452.htm
- in.gov.br/web/dou/…/instrucao-normativa-359448244
- planalto.gov.br/ccivil_03/leis/…/l9093.htm
- bcb.gov.br/estabilidadefinanceira/exibenormativo
- alerjln1.alerj.rj.gov.br/contlei.nsf/f25edae7e64db53b032564fe005262ef/…/46837e4d22b01f3503258d2c0048abda
- in.gov.br/web/dou/…/portaria-mgi-n-11.460-de-29-de-dezembro-de-2025-678388627
- legis.ac.gov.br/detalhar/1087
- legis.ac.gov.br/detalhar/1828
- legis.ac.gov.br/detalhar/618
- legis.ac.gov.br/detalhar/940
- legis.ac.gov.br/detalhar/688
- sapl.al.al.leg.br/norma/3363
- sapl.al.al.leg.br/norma/3364
- sapl.al.al.leg.br/norma/3117
- al.ap.leg.br/ver_texto_lei.php
- silegis.al.ap.leg.br/proposicaopdf/2CEatualizadaeconsolidadaateEC071comSumario.pdf
- al.ap.leg.br/ver_texto_lei.php
- sapl.al.am.leg.br/norma/8919
- sapl.al.am.leg.br/norma/2873
- sapl.cmm.am.gov.br/norma/3932
- legislabahia.ba.gov.br/documentos/constituicao-do-estado-da-bahia-de-05-de-outubro-de-1989
- belt.al.ce.gov.br/index.php/constituicao-do-ceara/…/5643-emenda-constitucional-n-73-de-1-de-dezembro-de-2011-d-o-06-12-11
- sinj.df.gov.br/sinj/Norma/…/Lei_72_27_12_1989.html
- sinj.df.gov.br/sinj/Norma/…/Lei_963_1995.html
- www3.al.es.gov.br/Arquivo/Documents/…/LEI110102019.html
- legisla.casacivil.go.gov.br/pesquisa_legislacao/100979/…/lei-20756
- arquivos.al.ma.leg.br/ged/legislacao/…/LEI_2457
- al.mt.gov.br/norma-juridica/urn:lex:br;mato.grosso:estadual:lei.ordinaria:2002-12-27;7879
- aacpdappls.net.ms.gov.br/appls/legislacao/…/a489a293563f506304256e450002e9f8
- bancodeleis.alepa.pa.gov.br/arquivos/lei5999_1996_93239.pdf
- sapl.al.pb.leg.br/norma/11988
- legislacao.pr.gov.br/legislacao/pesquisarAto.do
- legis.alepe.pe.gov.br/texto.aspx
- sapl.al.pi.leg.br/norma/5849
- alerjln1.alerj.rj.gov.br/CONTLEI.NSF/c8aa0900025feef6032564ec0060dfff/…/1baf90ca125ff96f8325740a00776600
- portal.stf.jus.br/processos/detalhe.asp
- alerjln1.alerj.rj.gov.br/CONTLEI.NSF/69d90307244602bb032567e800668618/…/80a541c3a5a9d63183256c7d0057bf25
- portal.stf.jus.br/processos/detalhe.asp
- al.rn.leg.br/storage/legislacao/…/arq5064574f632ec.pdf
- al.rn.leg.br/noticia/19157/…/rn-faz-519-anos-e-data-foi-criada-por-lei-estadual-em-alusao-ao-marco-de-touros
- ww2.al.rs.gov.br/dal/LinkClick.aspx
- ww2.al.rs.gov.br/dal/Legislação/…/Default.aspx
- sapl.al.ro.leg.br/norma/4958
- sapl.al.ro.leg.br/norma/3003
- portal.stf.jus.br/processos/detalhe.asp
- sapl.al.rr.leg.br/media/sapl/…/constituicao_estadual_do_estado_de_roraima.pdf
- leis.alesc.sc.gov.br/html/2022/…/18531_2022_lei.html
- leis.alesc.sc.gov.br/html/1996/…/10306_1996_lei.html
- leis.alesc.sc.gov.br/html/1999/…/11213_1999_lei.html
- leis.alesc.sc.gov.br/html/2004/…/12906_2004_lei.html
- leis.alesc.sc.gov.br/html/2005/…/13408_2005_lei.html
- al.sp.gov.br/repositorio/legislacao/…/lei-9497-05.03.1997.html
- al.sp.gov.br/repositorio/legislacao/…/lei-17746-12.09.2023.html
- aleselegis.al.se.leg.br/Arquivo/Documents/…/CE11989.html
- al.to.leg.br/arquivo/15717
- al.to.leg.br/arquivo/15724
- al.to.leg.br/arquivo/6883
- al.to.leg.br/arquivo/6358
- planalto.gov.br/ccivil_03/leis/…/l0662.htm
- planalto.gov.br/ccivil_03/leis/…/l10607.htm
- planalto.gov.br/ccivil_03/leis/…/L1266.htm
- planalto.gov.br/ccivil_03/leis/…/l6802.htm
- planalto.gov.br/ccivil_03/_ato2023-2026/…/l14759.htm
- portal.stf.jus.br/processos/detalhe.asp
- alerjln1.alerj.rj.gov.br/contlei.nsf/f25edae7e64db53b032564fe005262ef/…/063f7c027766eab48325744a007a4ab0
- arquivos.al.ma.leg.br/ged/legislacao/…/LEI_11539
- arquivos.al.ma.leg.br/ged/legislacao/…/LEI_12800
- legis.ac.gov.br/detalhar/2249
- legisweb.com.br/legislacao
- diario.imprensaoficial.al.gov.br/apinova/api/…/24602
- al.ap.leg.br/ver_texto_lei.php
- al.ap.leg.br/ver_texto_lei.php
- al.ap.leg.br/ver_texto_lei.php
- sapl.al.pb.leg.br/media/sapl/…/2945_texto_integral.pdf
- legislacao.pr.gov.br/legislacao/exibirAto.do
- legis.alepe.pe.gov.br/texto.aspx
- diario.imprensaoficial.am.gov.br/portal/edicoes/…/17974
- legisla.casacivil.go.gov.br/api/v2/…/115759
- planalto.gov.br/ccivil_03/leis/…/l4737compilado.htm
- planalto.gov.br/ccivil_03/constituicao/…/emc16.htm
- planalto.gov.br/ccivil_03/constituicao/…/emc107.htm
Last updated on
