colombian-holidays 1.8.0 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -66,23 +66,71 @@ The content of the `colombianHolidays2015` variable will be the following array:
66
66
  ```
67
67
  <!-- prettier-ignore-end -->
68
68
 
69
+ You can opt-in to have the function return native JavaScript dates instead of strings for the `date` and `celebrationDate` properties by using the `returnNativeDate` option:
70
+
71
+ <!-- prettier-ignore-start -->
72
+
73
+ ```js
74
+ const colombianHolidays2015 = colombianHolidays(2015, { returnNativeDate });
75
+ ```
76
+
69
77
  If the year is omitted, by default the function will return the holidays for the current year:
70
78
 
71
79
  ```js
72
80
  const currentYearHolidays = colombianHolidays();
73
81
  ```
74
82
 
75
- ### TypeScript
83
+ ## Utils
76
84
 
77
- The module is written in TypeScript and type definitions files are included.
85
+ The package provides two helper functions which can be imported from `lib/utils`:
86
+
87
+ ### isHoliday
78
88
 
79
- ## Contributing
89
+ Returns true if the given date is a colombian holiday, otherwise returns false.
80
90
 
81
- Contributions, issues and feature requests are welcome!
91
+ ```js
92
+ import { isHoliday } from 'colombian-holidays/lib/utils/isHoliday`
93
+
94
+ const date = new Date("2018-01-01T05:00:00.000Z")
82
95
 
83
- ## Show your support
96
+ if (isHoliday(date)) {
97
+ console.log('it is a colombian holiday');
98
+ } else {
99
+ console.log('it is NOT a colombian holiday');
100
+ }
101
+ ```
84
102
 
85
- Give a ⭐️ if you like this project!
103
+ ### holidaysWithinInterval
104
+
105
+ Returns an with the colombian holidays within two dates:
106
+
107
+ ```js
108
+ import { holidaysWithinInterval } from 'colombian-holidays/lib/utils/holidaysWithinInterval`
109
+
110
+ const start = new Date("2021-01-01");
111
+ const end = new Date("2021-01-11");
112
+ const holidays = holidaysWithinInterval({ start, end });
113
+ /*
114
+ [
115
+ {
116
+ celebrationDate: "2021-01-01",
117
+ date: "2021-01-01",
118
+ name: "Año Nuevo",
119
+ nextMonday: false,
120
+ },
121
+ {
122
+ celebrationDate: "2021-01-11",
123
+ date: "2021-01-06",
124
+ name: "Reyes Magos",
125
+ nextMonday: true,
126
+ },
127
+ ]
128
+ */
129
+ ```
130
+
131
+ ### TypeScript
132
+
133
+ The module is written in TypeScript and type definitions files are included.
86
134
 
87
135
  ## License
88
136
 
@@ -0,0 +1,4 @@
1
+ import type { Holiday, ColombianHoliday } from "./types";
2
+ export declare const NEW_HOLIDAY_SCHEMA_START_YEAR = 1984;
3
+ declare function getHoliday(holiday: Holiday, year: number): ColombianHoliday;
4
+ export default getHoliday;
package/lib/helpers.js ADDED
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.NEW_HOLIDAY_SCHEMA_START_YEAR = void 0;
7
+ const pascua_1 = __importDefault(require("pascua"));
8
+ // 1984 is the year when the current holidays scheme is enforced
9
+ // http://www.alcaldiabogota.gov.co/sisjur/normas/Norma1.jsp?i=4954
10
+ exports.NEW_HOLIDAY_SCHEMA_START_YEAR = 1984;
11
+ function getNextDayOfWeek(date, dayOfWeek) {
12
+ const resultDate = new Date(date);
13
+ resultDate.setDate(date.getDate() + ((7 + dayOfWeek - date.getDay()) % 7));
14
+ return resultDate;
15
+ }
16
+ function getNextMonday(date) {
17
+ const MONDAY = 1;
18
+ return getNextDayOfWeek(date, MONDAY);
19
+ }
20
+ function isEasterHoliday(holiday) {
21
+ return "offset" in holiday;
22
+ }
23
+ function getHolidayDate(holiday, year) {
24
+ if (isEasterHoliday(holiday)) {
25
+ const { month, day } = (0, pascua_1.default)(year);
26
+ return new Date(year, month - 1, day + holiday.offset);
27
+ }
28
+ const [month, day] = holiday.date.split("-");
29
+ return new Date(year, Number(month) - 1, Number(day));
30
+ }
31
+ function formatDate(date) {
32
+ const year = date.getFullYear();
33
+ const month = String(date.getMonth() + 1).padStart(2, "0");
34
+ const day = String(date.getDate()).padStart(2, "0");
35
+ return `${year}-${month}-${day}`;
36
+ }
37
+ function getHoliday(holiday, year) {
38
+ const holidayDate = getHolidayDate(holiday, year);
39
+ const celebrationDate = year >= exports.NEW_HOLIDAY_SCHEMA_START_YEAR && holiday.nextMonday
40
+ ? getNextMonday(holidayDate)
41
+ : holidayDate;
42
+ return {
43
+ date: formatDate(holidayDate),
44
+ celebrationDate: formatDate(celebrationDate),
45
+ name: holiday.name,
46
+ nextMonday: year >= exports.NEW_HOLIDAY_SCHEMA_START_YEAR && holiday.nextMonday,
47
+ };
48
+ }
49
+ exports.default = getHoliday;
50
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAG5B,gEAAgE;AAChE,mEAAmE;AACtD,QAAA,6BAA6B,GAAG,IAAI,CAAC;AAElD,SAAS,gBAAgB,CAAC,IAAU,EAAE,SAAiB;IACrD,MAAM,UAAU,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;IAClC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAC3E,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,SAAS,aAAa,CAAC,IAAU;IAC/B,MAAM,MAAM,GAAG,CAAC,CAAC;IACjB,OAAO,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACxC,CAAC;AAED,SAAS,eAAe,CAAC,OAAgB;IACvC,OAAO,QAAQ,IAAI,OAAO,CAAC;AAC7B,CAAC;AAED,SAAS,cAAc,CAAC,OAAgB,EAAE,IAAY;IACpD,IAAI,eAAe,CAAC,OAAO,CAAC,EAAE;QAC5B,MAAM,EAAE,KAAK,EAAE,GAAG,EA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CAAC,UAAU;KACxE,CAAC;AACJ,CAAC;AAED,kBAAe,UAAU,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { DateHoliday, EasterHoliday } from "./types";
2
+ declare const _default: (DateHoliday | EasterHoliday)[];
3
+ export default _default;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const dateHolidays = [
4
+ { date: "01-01", name: "Año Nuevo", nextMonday: false },
5
+ { date: "05-01", name: "Día del Trabajo", nextMonday: false },
6
+ { date: "07-20", name: "Grito de la Independencia", nextMonday: false },
7
+ { date: "08-07", name: "Batalla de Boyacá", nextMonday: false },
8
+ { date: "12-08", name: "Inmaculada Concepción", nextMonday: false },
9
+ { date: "12-25", name: "Navidad", nextMonday: false },
10
+ { date: "01-06", name: "Reyes Magos", nextMonday: true },
11
+ { date: "03-19", name: "San José", nextMonday: true },
12
+ { date: "06-29", name: "San Pedro y San Pablo", nextMonday: true },
13
+ { date: "08-15", name: "Asunción de la Virgen", nextMonday: true },
14
+ { date: "10-12", name: "Día de la Raza", nextMonday: true },
15
+ { date: "11-01", name: "Todos los Santos", nextMonday: true },
16
+ { date: "11-11", name: "Independencia de Cartagena", nextMonday: true },
17
+ ];
18
+ // We could simplify the calculation by setting the offset to match Monday.
19
+ // For example, the date for the 'Corpus Christi' is 60 days after Easter
20
+ // and that's the date it is celebrated in most countries. In Colombia,
21
+ // that date is moved to the next monday, hence, we use 60 for the offset
22
+ // and then get the next monday instead of directly using 64 as the offset.
23
+ // https://www.alcaldiabogota.gov.co/sisjur/normas/Norma1.jsp?i=4954
24
+ const easterHolidays = [
25
+ { offset: -3, name: "Jueves Santo", nextMonday: false },
26
+ { offset: -2, name: "Viernes Santo", nextMonday: false },
27
+ { offset: 39, name: "Ascensión del Señor", nextMonday: true },
28
+ { offset: 60, name: "Corpus Christi", nextMonday: true },
29
+ { offset: 68, name: "Sagrado Corazón de Jesús", nextMonday: true },
30
+ ];
31
+ exports.default = [...dateH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AAE,4BAA4B,EAAE,UAAU,EAAE,IAAI,EAAE;CACxE,CAAC;AAEF,2EAA2E;AAC3E,yEAAyE;AACzE,uEAAuE;AACvE,yEAAyE;AACzE,2EAA2E;AAC3E,oEAAoE;AACpE,MAAM,cAAc,GAAoB;IACtC,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,UAAU,EAAE,KAAK,EAAE;IACvD,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,UAAU,EAAE,KAAK,EAAE;IACxD,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,qBAAqB,EAAE,UAAU,EAAE,IAAI,EAAE;IAC7D,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,UAAU,EAAE,IAAI,EAAE;IACxD,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,0BAA0B,EAAE,UAAU,EAAE,IAAI,EAAE;CACnE,CAAC;AAEF,kBAAe,CAAC,GAAG,YAAY,EAAE,GAAG,cAAc,CAAC,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { ColombianHoliday } from "./types";
2
+ export declare const FIRST_HOLIDAY_YEAR = 1583;
3
+ export declare const LAST_HOLIDAY_YEAR = 4099;
4
+ declare function colombianHolidays(year?: number): ColombianHoliday[];
5
+ export default colombianHolidays;
package/lib/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.LAST_HOLIDAY_YEAR = exports.FIRST_HOLIDAY_YEAR = void 0;
7
+ const helpers_1 = __importDefault(require("./helpers"));
8
+ const holidays_1 = __importDefault(require("./holidays"));
9
+ // pascua package year limits
10
+ exports.FIRST_HOLIDAY_YEAR = 1583;
11
+ exports.LAST_HOLIDAY_YEAR = 4099;
12
+ function colombianHolidays(year = new Date().getFullYear()) {
13
+ if (year < exports.FIRST_HOLIDAY_YEAR || year > exports.LAST_HOLIDAY_YEAR) {
14
+ throw new Error(`The year should be between ${exports.FIRST_HOLIDAY_YEAR} and ${exports.LAST_HOLIDAY_YEAR}`);
15
+ }
16
+ return holidays_1.default
17
+ .map((holiday) => (0, helpers_1.default)(holiday, year))
18
+ .sort((a, b) => a.celebrationDate.localeCompare(b.celebrationDate));
19
+ }
20
+ exports.default = colombianHolidays;
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAmC;AACnC,0DAAkC;AAGlC,6BAA6B;AAChB,QAAA,kBAAkB,GAAG,IAAI,CAAC;AAC1B,QAAA,iBAAiB,GAAG,IAAI,CAAC;AAEtC,SAAS,iBAAiB,CACxB,OAAe,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;IAEvC,IAAI,IAAI,GAAG,0BAAkB,IAAI,IAAI,GAAG,yBAAiB,EAAE;QACzD,MAAM,IAAI,KAAK,CACb,8BAA8B,0BAAkB,QAAQ,yBAAiB,EAAE,CAC5E,CAAC;KACH;IAED,OAAO,kBAAQ;SACZ,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAA,iBAAU,EAAC,OAAO,EAAE,IAAI,CAAC,CAAC;SAC3C,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC;AACxE,CAAC;AAED,kBAAe,iBAAiB,CAAC"}
package/lib/types.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ export interface BasicHoliday {
2
+ name: string;
3
+ nextMonday: boolean;
4
+ }
5
+ export interface DateHoliday extends BasicHoliday {
6
+ date: string;
7
+ }
8
+ export interface EasterHoliday extends BasicHoliday {
9
+ offset: number;
10
+ }
11
+ export interface ColombianHoliday extends BasicHoliday {
12
+ date: string;
13
+ celebrationDate: string;
14
+ }
15
+ export type Holiday = DateHoliday | EasterHoliday;
package/lib/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/lib/utils.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function isHoliday(date: Date): boolean;
package/lib/utils.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isHoliday = void 0;
7
+ const _1 = __importDefault(require("."));
8
+ function isHoliday(date) {
9
+ return (0, _1.default)(date.getUTCFullYear()).some(({ celebrationDate }) => {
10
+ const d = new Date(celebrationDate);
11
+ return (d.getUTCDate() === date.getUTCDate() &&
12
+ d.getUTCMonth() === date.getUTCMonth() &&
13
+ d.getUTCFullYear() === date.getUTCFullYear());
14
+ });
15
+ }
16
+ exports.isHoliday = isHoliday;
17
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAkC;AAElC,SAAgB,SAAS,CAAC,IAAU;IAClC,OAAO,IAAA,UAAiB,EAAC,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC,IAAI,CAClD,CAAC,EAAE,eAAe,EAAE,EAAE,EAAE;QACtB,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,eAAe,CAAC,CAAC;QACpC,OAAO,CACL,CAAC,CAAC,UAAU,EAAE,KAAK,IAAI,CAAC,UAAU,EAAE;YACpC,CAAC,CAAC,WAAW,EAAE,KAAK,IAAI,CAAC,WAAW,EAAE;YACtC,CAAC,CAAC,cAAc,EAAE,KAAK,IAAI,CAAC,cAAc,EAAE,CAC7C,CAAC;IACJ,CAAC,CACF,CAAC;AACJ,CAAC;AAXD,8BAWC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "colombian-holidays",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "description": "Colombian holidays",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {