holidays-cs
Advanced tools
+1
-1
@@ -1,2 +0,2 @@ | ||
| import { DateTime, Interval } from "luxon"; | ||
| import { DateTime, Interval } from 'luxon'; | ||
| /** | ||
@@ -3,0 +3,0 @@ * Returns the date of Easter Monday for a given year. |
+28
-28
@@ -1,2 +0,2 @@ | ||
| import { DateTime, Interval } from "luxon"; | ||
| import { DateTime, Interval } from 'luxon'; | ||
| /** | ||
@@ -29,16 +29,16 @@ * Returns the date of Easter Monday for a given year. | ||
| export function getEasterSunday(year) { | ||
| let a = year % 19; | ||
| let b = Math.floor(year / 100); | ||
| let c = year % 100; | ||
| let d = Math.floor(b / 4); | ||
| let e = b % 4; | ||
| let f = Math.floor((b + 8) / 25); | ||
| let g = Math.floor((b - f + 1) / 3); | ||
| let h = (19 * a + b - d - g + 15) % 30; | ||
| let i = Math.floor(c / 4); | ||
| let k = c % 4; | ||
| let l = (32 + 2 * e + 2 * i - h - k) % 7; | ||
| let m = Math.floor((a + 11 * h + 22 * l) / 451); | ||
| let month = Math.floor((h + l - 7 * m + 114) / 31); | ||
| let day = ((h + l - 7 * m + 114) % 31) + 1; | ||
| const a = year % 19; | ||
| const b = Math.floor(year / 100); | ||
| const c = year % 100; | ||
| const d = Math.floor(b / 4); | ||
| const e = b % 4; // eslint-disable-line unicorn/prevent-abbreviations | ||
| const f = Math.floor((b + 8) / 25); | ||
| const g = Math.floor((b - f + 1) / 3); | ||
| const h = ((19 * a) + b - d - g + 15) % 30; | ||
| const i = Math.floor(c / 4); | ||
| const k = c % 4; | ||
| const l = (32 + (2 * e) + (2 * i) - h - k) % 7; | ||
| const m = Math.floor((a + (11 * h) + (22 * l)) / 451); | ||
| const month = Math.floor((h + l - (7 * m) + 114) / 31); | ||
| const day = ((h + l - (7 * m) + 114) % 31) + 1; | ||
| return DateTime.fromObject({ year, month, day }); | ||
@@ -90,6 +90,5 @@ } | ||
| export function getHollyWeekInterval(year) { | ||
| let easter = getEaster(year); | ||
| const easter = getEaster(year); | ||
| return Interval.fromDateTimes(easter.minus({ days: 7 }), // Palm Sunday | ||
| easter.plus({ days: 1 }) // Easter Monday | ||
| ); | ||
| easter.plus({ days: 1 })); | ||
| } | ||
@@ -103,4 +102,5 @@ /** | ||
| const interval = getHollyWeekInterval(date.year); | ||
| if (!interval.isValid) | ||
| if (!interval.isValid) { | ||
| return false; | ||
| } | ||
| return interval.start && interval.end ? interval.start <= date && date <= interval.end : false; | ||
@@ -112,11 +112,11 @@ } | ||
| const names = { | ||
| "-7": "Květná neděle", | ||
| "-6": "Modré pondělí", | ||
| "-5": "Šedivé úterý", | ||
| "-4": "Škaredá středa", | ||
| "-3": "Zelený čtvrtek", | ||
| "-2": "Velký pátek", | ||
| "-1": "Bílá sobota", | ||
| "0": "Velikonoční neděle", | ||
| "1": "Velikonoční pondělí", | ||
| '-7': 'Květná neděle', | ||
| '-6': 'Modré pondělí', | ||
| '-5': 'Šedivé úterý', | ||
| '-4': 'Škaredá středa', | ||
| '-3': 'Zelený čtvrtek', | ||
| '-2': 'Velký pátek', | ||
| '-1': 'Bílá sobota', | ||
| 0: 'Velikonoční neděle', | ||
| 1: 'Velikonoční pondělí', | ||
| }; | ||
@@ -123,0 +123,0 @@ /** |
+13
-14
@@ -1,3 +0,3 @@ | ||
| import { DateTime } from "luxon"; | ||
| interface Easter { | ||
| import { DateTime } from 'luxon'; | ||
| export type EasterMetadata = { | ||
| name: string | undefined; | ||
@@ -8,16 +8,16 @@ isGoodFriday: boolean; | ||
| isEasterMonday: boolean; | ||
| } | ||
| interface ShopsStatus { | ||
| areOpen: boolean; | ||
| status: string; | ||
| } | ||
| interface DayMetadata { | ||
| }; | ||
| export type DayMetadata = { | ||
| names: string[] | undefined; | ||
| isSignificantDay: boolean; | ||
| significantDay: string | undefined; | ||
| significantDay?: string | undefined; | ||
| isPublicHoliday: boolean; | ||
| publicHoliday: string | undefined; | ||
| easter: Easter | undefined; | ||
| shops: ShopsStatus; | ||
| } | ||
| publicHoliday?: string | undefined; | ||
| isHolyWeek: boolean; | ||
| easter?: EasterMetadata | undefined; | ||
| shops: { | ||
| areOpen: boolean; | ||
| status: string; | ||
| }; | ||
| }; | ||
| /** | ||
@@ -28,2 +28,1 @@ * Get metadata for a specific day | ||
| export declare function getDayMeta(date: DateTime | Date): DayMetadata; | ||
| export {}; |
+28
-26
@@ -1,7 +0,7 @@ | ||
| import { DateTime } from "luxon"; | ||
| import { getNameDayArray } from "./names.js"; | ||
| import { isPublicHoliday, getPublicHoliday } from "./holidays.js"; | ||
| import { getSignificantDay, isSignificantDay } from "./significant.js"; | ||
| import { areShopsOpen, getShopsStatus } from "./shops.js"; | ||
| import { getEasterDayName, isEasterMonday, isEasterSunday, isGoodFriday, isHolySaturday, isHolyWeek } from "./easter.js"; | ||
| import { DateTime } from 'luxon'; | ||
| import { getNameDayArray } from './names.js'; | ||
| import { getPublicHoliday, isPublicHoliday } from './holidays.js'; | ||
| import { getSignificantDay, isSignificantDay } from './significant.js'; | ||
| import { areShopsOpen, getShopsStatus } from './shops.js'; | ||
| import { getEasterDayName, isEasterMonday, isEasterSunday, isGoodFriday, isHolySaturday, isHolyWeek, } from './easter.js'; | ||
| /** | ||
@@ -13,5 +13,23 @@ * Get metadata for a specific day | ||
| date = date instanceof Date ? DateTime.fromJSDate(date) : date; | ||
| let easter = undefined; | ||
| if (isHolyWeek(date)) { | ||
| easter = { | ||
| const meta = { | ||
| names: getNameDayArray(date), | ||
| // Flags | ||
| isSignificantDay: isSignificantDay(date), | ||
| isPublicHoliday: isPublicHoliday(date), | ||
| // Easter | ||
| isHolyWeek: isHolyWeek(date), | ||
| // Shops | ||
| shops: { | ||
| areOpen: areShopsOpen(date), | ||
| status: getShopsStatus(date), | ||
| }, | ||
| }; | ||
| if (meta.isSignificantDay) { | ||
| meta.significantDay = getSignificantDay(date); | ||
| } | ||
| if (meta.isPublicHoliday) { | ||
| meta.publicHoliday = getPublicHoliday(date); | ||
| } | ||
| if (meta.isHolyWeek) { | ||
| meta.easter = { | ||
| name: getEasterDayName(date), | ||
@@ -24,19 +42,3 @@ isGoodFriday: isGoodFriday(date), | ||
| } | ||
| let shops = { | ||
| areOpen: areShopsOpen(date), | ||
| status: getShopsStatus(date) | ||
| }; | ||
| return { | ||
| names: getNameDayArray(date), | ||
| // easter metadata | ||
| easter: easter, | ||
| // national significant days | ||
| isSignificantDay: isSignificantDay(date), | ||
| significantDay: getSignificantDay(date), | ||
| // national holidays | ||
| isPublicHoliday: isPublicHoliday(date), | ||
| publicHoliday: getPublicHoliday(date), | ||
| // shops metadata | ||
| shops: shops | ||
| }; | ||
| return meta; | ||
| } |
@@ -1,2 +0,2 @@ | ||
| import { DateTime } from "luxon"; | ||
| import { DateTime } from 'luxon'; | ||
| /** | ||
@@ -3,0 +3,0 @@ * Check if the given date is a holiday |
+15
-15
@@ -1,15 +0,15 @@ | ||
| import { DateTime } from "luxon"; | ||
| import { isEasterMonday, isGoodFriday } from "./easter.js"; | ||
| import { DateTime } from 'luxon'; | ||
| import { isEasterMonday, isGoodFriday } from './easter.js'; | ||
| const holidays = { | ||
| "0101": "Den obnovy samostatného českého státu", | ||
| "0105": "Svátek práce", | ||
| "0805": "Den vítězství (1945)", | ||
| "0507": "Den slovanských věrozvěstů Cyrila a Metoděje", | ||
| "0607": "Den upálení mistra Jana Husa (1415)", | ||
| "2809": "Den české státnosti", | ||
| "2810": "Den vzniku samostatného československého státu (1918)", | ||
| "1711": "Den boje za svobodu a demokracii (1939 a 1989)", | ||
| "2412": "Štědrý den", | ||
| "2512": "První svátek vánoční", | ||
| "2612": "Druhý svátek vánoční" | ||
| '0101': 'Den obnovy samostatného českého státu', | ||
| '0105': 'Svátek práce', | ||
| '0805': 'Den vítězství (1945)', | ||
| '0507': 'Den slovanských věrozvěstů Cyrila a Metoděje', | ||
| '0607': 'Den upálení mistra Jana Husa (1415)', | ||
| 2809: 'Den české státnosti', | ||
| 2810: 'Den vzniku samostatného československého státu (1918)', | ||
| 1711: 'Den boje za svobodu a demokracii (1939 a 1989)', | ||
| 2412: 'Štědrý den', | ||
| 2512: 'První svátek vánoční', | ||
| 2612: 'Druhý svátek vánoční', | ||
| }; | ||
@@ -31,8 +31,8 @@ /** | ||
| if (isEasterMonday(date)) { | ||
| return "Velikonoční pondělí"; | ||
| return 'Velikonoční pondělí'; | ||
| } | ||
| if (isGoodFriday(date)) { | ||
| return "Velký pátek"; | ||
| return 'Velký pátek'; | ||
| } | ||
| return holidays[date.toFormat('ddMM')]; | ||
| } |
+8
-8
@@ -1,8 +0,8 @@ | ||
| export * from "./easter.js"; | ||
| export * from "./holidays.js"; | ||
| export * from "./fathers-day.js"; | ||
| export * from "./mothers-day.js"; | ||
| export * from "./names.js"; | ||
| export * from "./significant.js"; | ||
| export * from "./shops.js"; | ||
| export * from "./get-meta.js"; | ||
| export * from './easter.js'; | ||
| export * from './holidays.js'; | ||
| export * from './fathers-day.js'; | ||
| export * from './mothers-day.js'; | ||
| export * from './names.js'; | ||
| export * from './significant.js'; | ||
| export * from './shops.js'; | ||
| export * from './get-meta.js'; |
+8
-8
@@ -1,8 +0,8 @@ | ||
| export * from "./easter.js"; | ||
| export * from "./holidays.js"; | ||
| export * from "./fathers-day.js"; | ||
| export * from "./mothers-day.js"; | ||
| export * from "./names.js"; | ||
| export * from "./significant.js"; | ||
| export * from "./shops.js"; | ||
| export * from "./get-meta.js"; | ||
| export * from './easter.js'; | ||
| export * from './holidays.js'; | ||
| export * from './fathers-day.js'; | ||
| export * from './mothers-day.js'; | ||
| export * from './names.js'; | ||
| export * from './significant.js'; | ||
| export * from './shops.js'; | ||
| export * from './get-meta.js'; |
+1
-1
@@ -1,2 +0,2 @@ | ||
| import { DateTime } from "luxon"; | ||
| import { DateTime } from 'luxon'; | ||
| /** | ||
@@ -3,0 +3,0 @@ * Get names as a string for the given date |
+3
-4
@@ -1,4 +0,3 @@ | ||
| // @ts-ignore | ||
| import data from './names.json' assert { type: "json" }; | ||
| import { DateTime } from "luxon"; | ||
| import { DateTime } from 'luxon'; | ||
| import data from './names.json' assert { type: 'json' }; | ||
| const names = data; | ||
@@ -12,3 +11,3 @@ /** | ||
| date = date instanceof Date ? DateTime.fromJSDate(date) : date; | ||
| return getNameDayArray(date)?.join(joinWith) || ''; | ||
| return getNameDayArray(date)?.join(joinWith) ?? ''; | ||
| } | ||
@@ -15,0 +14,0 @@ /** |
+1
-1
@@ -1,2 +0,2 @@ | ||
| import { DateTime } from "luxon"; | ||
| import { DateTime } from 'luxon'; | ||
| /** | ||
@@ -3,0 +3,0 @@ * Returns the shop status for the given date. |
+13
-13
@@ -1,3 +0,3 @@ | ||
| import { DateTime } from "luxon"; | ||
| import { isEasterMonday } from "./easter.js"; | ||
| import { DateTime } from 'luxon'; | ||
| import { isEasterMonday } from './easter.js'; | ||
| /** | ||
@@ -8,8 +8,8 @@ * List of days when the shop is closed. | ||
| const closed = { | ||
| "0101": "Nový rok", | ||
| "0805": "Den vítězství", | ||
| "2809": "Den české státnosti", | ||
| "2810": "Den vzniku samostatného československého státu", | ||
| "2512": "1. svátek vánoční", | ||
| "2612": "2. svátek vánoční", | ||
| '0101': 'Nový rok', | ||
| '0805': 'Den vítězství', | ||
| 2809: 'Den české státnosti', | ||
| 2810: 'Den vzniku samostatného československého státu', | ||
| 2512: '1. svátek vánoční', | ||
| 2612: '2. svátek vánoční', | ||
| }; | ||
@@ -24,10 +24,10 @@ /** | ||
| if (isEasterMonday(date)) { | ||
| return "zavřeno"; | ||
| return 'zavřeno'; | ||
| } | ||
| // Christmas Eve | ||
| if (date.toFormat('ddMM') === '2412') { | ||
| return "otevřeno do 12:00"; | ||
| return 'otevřeno do 12:00'; | ||
| } | ||
| // other closed days | ||
| return date.toFormat('ddMM') in closed ? "zavřeno" : "otevřeno"; | ||
| // Other closed days | ||
| return date.toFormat('ddMM') in closed ? 'zavřeno' : 'otevřeno'; | ||
| } | ||
@@ -40,3 +40,3 @@ /** | ||
| date = date instanceof Date ? DateTime.fromJSDate(date) : date; | ||
| return getShopsStatus(date).startsWith("otevřeno"); | ||
| return getShopsStatus(date).startsWith('otevřeno'); | ||
| } |
@@ -1,2 +0,2 @@ | ||
| import { DateTime } from "luxon"; | ||
| import { DateTime } from 'luxon'; | ||
| /** | ||
@@ -3,0 +3,0 @@ * Returns the significant day for the given date. |
@@ -1,4 +0,3 @@ | ||
| // @ts-ignore | ||
| import data from './significant.json' assert { type: "json" }; | ||
| import { DateTime } from "luxon"; | ||
| import { DateTime } from 'luxon'; | ||
| import data from './significant.json' assert { type: 'json' }; | ||
| const significant = data; | ||
@@ -5,0 +4,0 @@ /** |
+17
-3
| { | ||
| "name": "holidays-cs", | ||
| "version": "0.0.8", | ||
| "version": "0.0.9", | ||
| "author": "Roman Ožana <roman@ozana.cz> (https://ozana.cz)", | ||
@@ -8,2 +8,10 @@ "repository": "git@github.com:OzzyCzech/holidays-cs.git", | ||
| "description": "Public holidays, Easter, name days and important days in the Czech Republic.", | ||
| "keywords": [ | ||
| "czechia", | ||
| "czech republic", | ||
| "public holidays", | ||
| "holidays", | ||
| "name day", | ||
| "easter" | ||
| ], | ||
| "type": "module", | ||
@@ -17,4 +25,4 @@ "exports": { | ||
| "ava": "NODE_OPTIONS='--import=tsx/esm' ava", | ||
| "xo": "xo *.js", | ||
| "test": "xo && tsc --noEmit && ava" | ||
| "xo": "xo", | ||
| "test": "xo && tsc --noEmit && NODE_OPTIONS='--import=tsx/esm' ava" | ||
| }, | ||
@@ -54,3 +62,9 @@ "engines": { | ||
| ] | ||
| }, | ||
| "xo": { | ||
| "rules": { | ||
| "@typescript-eslint/naming-convention": "off", | ||
| "quote-props": "off" | ||
| } | ||
| } | ||
| } |
+11
-2
@@ -127,2 +127,10 @@ # Holidays (cs) | ||
| You can get all public holidays for a given year: | ||
| ```javascript | ||
| import {getPublicHolidaysList} from 'holidays-cs'; | ||
| getPublicHolidaysList(2024); // returns Map with all 13 holidays | ||
| ``` | ||
| ### Shops status | ||
@@ -149,4 +157,4 @@ | ||
| Father's day is celebrated on the **third Sunday in June**. | ||
| Mother's day is celebrated on the **second Sunday in May**. | ||
| Father's Day is celebrated on the **third Sunday in June**. | ||
| Mother's Day is celebrated on the **second Sunday in May**. | ||
@@ -168,2 +176,3 @@ ```javascript | ||
| - [date-holidays](https://github.com/commenthol/date-holidays) library for inspiration | ||
| - [Online calendar](https://calendar.center/) for verifying the data | ||
@@ -170,0 +179,0 @@ - [Easter dates calculation](https://github.com/paulzag/ZagZ-iCalendars) for the Easter dates |
33522
1.89%181
5.23%896
-0.11%