-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6458f40
commit b4104e7
Showing
5 changed files
with
135 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { holidaysWithinInterval } from "./holidaysWithinInterval"; | ||
|
||
describe("holidaysWithinInterval", () => { | ||
it("should return the correct number of holidays overlapping two years", () => { | ||
const start = new Date("2020-12-01"); | ||
const end = new Date("2021-01-15"); | ||
const result = holidaysWithinInterval({ end, start }); | ||
|
||
expect(result).toEqual([ | ||
{ | ||
celebrationDate: "2020-12-08", | ||
date: "2020-12-08", | ||
name: "Inmaculada Concepción", | ||
nextMonday: false, | ||
}, | ||
{ | ||
celebrationDate: "2020-12-25", | ||
date: "2020-12-25", | ||
name: "Navidad", | ||
nextMonday: false, | ||
}, | ||
{ | ||
celebrationDate: "2021-01-01", | ||
date: "2021-01-01", | ||
name: "Año Nuevo", | ||
nextMonday: false, | ||
}, | ||
{ | ||
celebrationDate: "2021-01-11", | ||
date: "2021-01-06", | ||
name: "Reyes Magos", | ||
nextMonday: true, | ||
}, | ||
]); | ||
}); | ||
|
||
it("should return the correct number of holidays inclusive", () => { | ||
const start = new Date("2021-01-01"); | ||
const end = new Date("2021-01-11"); | ||
const result = holidaysWithinInterval({ start, end }); | ||
|
||
expect(result).toEqual([ | ||
{ | ||
celebrationDate: "2021-01-01", | ||
date: "2021-01-01", | ||
name: "Año Nuevo", | ||
nextMonday: false, | ||
}, | ||
{ | ||
celebrationDate: "2021-01-11", | ||
date: "2021-01-06", | ||
name: "Reyes Magos", | ||
nextMonday: true, | ||
}, | ||
]); | ||
}); | ||
|
||
it("should return the correct number of holidays for a given year", () => { | ||
const start = new Date("2021-01-01"); | ||
const end = new Date("2021-12-31"); | ||
const result = holidaysWithinInterval({ start, end }); | ||
|
||
expect(result.length).toBe(18); | ||
}); | ||
|
||
it("should return the correct number of holidays overlapping three years", () => { | ||
const start = new Date("2014-07-20"); | ||
const end = new Date("2016-03-25"); | ||
const result = holidaysWithinInterval({ start, end }); | ||
|
||
expect(result.length).toBe(31); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import colombianHolidays from ".."; | ||
import { ColombianHoliday } from "../types"; | ||
|
||
export type Interval = { | ||
start: Date; | ||
end: Date; | ||
}; | ||
export function holidaysWithinInterval({ | ||
start, | ||
end, | ||
}: Interval): ColombianHoliday[] { | ||
const yearEnd = new Date(end).getUTCFullYear(); | ||
const yearStart = new Date(start).getUTCFullYear(); | ||
let holidays: ColombianHoliday[] = []; | ||
|
||
for (let i = yearStart; i <= yearEnd; i += 1) { | ||
holidays = holidays.concat(colombianHolidays(i)); | ||
} | ||
|
||
return holidays.filter(({ celebrationDate }) => { | ||
const date = new Date(celebrationDate); | ||
return date >= start && date <= end; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters