@@ -71,6 +71,94 @@ describe('getHolidays', () => {
7171 } )
7272} )
7373
74+ describe ( 'getHolidays with date range' , ( ) => {
75+ it ( 'returns holidays within a single-year range' , ( ) => {
76+ // 2025: Sexta-feira Santa (4/18), Tiradentes (4/21), Dia do Trabalho (5/1),
77+ // Corpus Christi (6/19), São João (6/24) = 5 holidays
78+ const result = getHolidays ( { start : makeAracajuDate ( 2025 , 4 , 1 ) , end : makeAracajuDate ( 2025 , 6 , 30 ) } )
79+ expect ( result ) . toHaveLength ( 5 )
80+ const names = result . map ( ( h ) => h . name )
81+ expect ( names ) . toContain ( 'Sexta-feira Santa' )
82+ expect ( names ) . toContain ( 'Tiradentes' )
83+ expect ( names ) . toContain ( 'Dia do Trabalho' )
84+ expect ( names ) . toContain ( 'Corpus Christi' )
85+ expect ( names ) . toContain ( 'São João' )
86+ } )
87+
88+ it ( 'includes holidays exactly on start and end bounds (inclusive)' , ( ) => {
89+ // Dia do Trabalho 2025 = May 1; São João 2025 = June 24
90+ const result = getHolidays ( { start : makeAracajuDate ( 2025 , 5 , 1 ) , end : makeAracajuDate ( 2025 , 6 , 24 ) } )
91+ const names = result . map ( ( h ) => h . name )
92+ expect ( names ) . toContain ( 'Dia do Trabalho' )
93+ expect ( names ) . toContain ( 'São João' )
94+ } )
95+
96+ it ( 'returns holidays across a cross-year range' , ( ) => {
97+ // 2024: Nossa Sra. da Conceição (12/8), Natal (12/25)
98+ // 2025: Confraternização Universal (1/1)
99+ const result = getHolidays ( { start : makeAracajuDate ( 2024 , 12 , 1 ) , end : makeAracajuDate ( 2025 , 1 , 31 ) } )
100+ expect ( result ) . toHaveLength ( 3 )
101+ const names = result . map ( ( h ) => h . name )
102+ expect ( names ) . toContain ( 'Nossa Sra. da Conceição' )
103+ expect ( names ) . toContain ( 'Natal' )
104+ expect ( names ) . toContain ( 'Confraternização Universal' )
105+ } )
106+
107+ it ( 'returns result sorted by date for cross-year ranges' , ( ) => {
108+ const result = getHolidays ( { start : makeAracajuDate ( 2024 , 12 , 1 ) , end : makeAracajuDate ( 2025 , 1 , 31 ) } )
109+ for ( let i = 1 ; i < result . length ; i ++ ) {
110+ expect ( result [ i ] . date . getTime ( ) ) . toBeGreaterThanOrEqual ( result [ i - 1 ] . date . getTime ( ) )
111+ }
112+ } )
113+
114+ it ( 'returns empty array when range contains no holidays' , ( ) => {
115+ // 2025-03-11 to 2025-03-16 — Carnaval acabou (3/3–3/4); próximo é Aniversário de Aracaju (3/17)
116+ const result = getHolidays ( { start : makeAracajuDate ( 2025 , 3 , 11 ) , end : makeAracajuDate ( 2025 , 3 , 16 ) } )
117+ expect ( result ) . toHaveLength ( 0 )
118+ } )
119+
120+ it ( 'returns empty array when start is after end' , ( ) => {
121+ const result = getHolidays ( { start : makeAracajuDate ( 2025 , 6 , 1 ) , end : makeAracajuDate ( 2025 , 3 , 1 ) } )
122+ expect ( result ) . toHaveLength ( 0 )
123+ } )
124+
125+ it ( 'returns a single holiday when range is one day and it is a holiday' , ( ) => {
126+ const result = getHolidays ( { start : makeAracajuDate ( 2025 , 12 , 25 ) , end : makeAracajuDate ( 2025 , 12 , 25 ) } )
127+ expect ( result ) . toHaveLength ( 1 )
128+ expect ( result [ 0 ] . name ) . toBe ( 'Natal' )
129+ } )
130+
131+ it ( 'returns empty array when range is one day and it is not a holiday' , ( ) => {
132+ const result = getHolidays ( { start : makeAracajuDate ( 2025 , 3 , 10 ) , end : makeAracajuDate ( 2025 , 3 , 10 ) } )
133+ expect ( result ) . toHaveLength ( 0 )
134+ } )
135+
136+ it ( 'normalizes UTC date input via toAracajuDate' , ( ) => {
137+ // 2025-01-01T03:00:00Z = 2025-01-01 00:00 Aracaju — inclui Confraternização
138+ const startUTC = new Date ( '2025-01-01T03:00:00Z' )
139+ const endUTC = new Date ( '2025-01-01T03:00:00Z' )
140+ const result = getHolidays ( { start : startUTC , end : endUTC } )
141+ expect ( result ) . toHaveLength ( 1 )
142+ expect ( result [ 0 ] . name ) . toBe ( 'Confraternização Universal' )
143+ } )
144+
145+ it ( 'does not include holiday when UTC midnight resolves to previous Aracaju day' , ( ) => {
146+ // 2025-01-01T00:00:00Z = 2024-12-31 21:00 Aracaju — Dec 31 não é feriado
147+ const startUTC = new Date ( '2025-01-01T00:00:00Z' )
148+ const endUTC = new Date ( '2025-01-01T00:00:00Z' )
149+ const result = getHolidays ( { start : startUTC , end : endUTC } )
150+ expect ( result ) . toHaveLength ( 0 )
151+ } )
152+
153+ it ( 'backward compat: numeric year still works' , ( ) => {
154+ expect ( getHolidays ( 2025 ) ) . toHaveLength ( 17 )
155+ } )
156+
157+ it ( 'backward compat: no argument still works' , ( ) => {
158+ expect ( Array . isArray ( getHolidays ( ) ) ) . toBe ( true )
159+ } )
160+ } )
161+
74162describe ( 'isBusinessDay' , ( ) => {
75163 it ( 'returns true for a regular weekday' , ( ) => {
76164 // 2025-03-10 Monday, not a holiday
0 commit comments