### Calculate business days with workdaysFromDate Source: https://context7.com/gaui/fridagar-node/llms.txt Demonstrates how to calculate the n-th business day before or after a reference date. It supports optional inclusion of half-day holidays and provides a practical example for calculating invoice due dates. ```typescript import { workdaysFromDate } from "fridagar"; const refDate = new Date("2024-12-23"); const secondWorkDay = workdaysFromDate(2, refDate); console.log(secondWorkDay.toISOString()); const secondWorkDayIncludingHalfDays = workdaysFromDate(2, refDate, true); console.log(secondWorkDayIncludingHalfDays.toISOString()); const newYearsDay = new Date("2025-01-01"); const prevBusinessDay = workdaysFromDate(-1, newYearsDay); console.log(prevBusinessDay.toISOString()); const thirdWorkDayFromToday = workdaysFromDate(3); console.log(thirdWorkDayFromToday); function calculateDueDate(invoiceDate: Date, netDays: number): Date { return workdaysFromDate(netDays, invoiceDate); } const invoice = new Date("2024-12-20"); const dueDate = calculateDueDate(invoice, 10); console.log(`Invoice due: ${dueDate.toISOString().slice(0, 10)}`); ``` -------------------------------- ### Implement localization using DayKey Source: https://context7.com/gaui/fridagar-node/llms.txt Shows how to map DayKey identifiers to localized strings and use them with the getAllDaysKeyed function to retrieve holiday data for a specific year. ```typescript import type { DayKey } from "fridagar"; import { getAllDaysKeyed } from "fridagar"; const dayNamesEnglish: Record = { nyars: "New Year's Day", skir: "Maundy Thursday", foslangi: "Good Friday", paska: "Easter Sunday", paska2: "Easter Monday", sumar1: "First Day of Summer", mai1: "Labour Day", uppst: "Ascension Day", hvitas: "Whit Sunday", hvitas2: "Whit Monday", jun17: "Icelandic National Day", verslm: "Commerce Day", adfanga: "Christmas Eve", jola: "Christmas Day", jola2: "Boxing Day", gamlars: "New Year's Eve", þrettand: "Epiphany", bonda: "Husband's Day", bollu: "Bun Day", sprengi: "Bursting Day", osku: "Ash Wednesday", valent: "Valentine's Day", konu: "Woman's Day", sjomanna: "Seamen's Day", sumsolst: "Summer Solstice", jonsm: "Midsummer", vetur1: "First Day of Winter", hrekkja: "Halloween", isltungu: "Icelandic Language Day", fullv: "Sovereignty Day", vetsolst: "Winter Solstice", thorl: "St. Thorlak's Day" }; const days2024 = getAllDaysKeyed(2024); const easterEnglish = dayNamesEnglish[days2024.paska.key]; console.log(easterEnglish); ``` -------------------------------- ### Map DayKeys to localized strings Source: https://github.com/gaui/fridagar-node/blob/master/README.md Shows how to use DayKey, HolidayKey, and SpecialDayKey union types to create type-safe dictionaries for translating holiday and special day names. ```typescript import type { DayKey, HolidayKey, SpecialDayKey } from "fridagar"; const holidayNamesPolish: Record = { nyars: "Nowy Rok", adfanga: "Wigilia", jola: "Boże Narodzenie", }; const specialDayNamesPolish: Record = { bollu: "Dzień Pączka", sjomanna: "Dzień Marynarza", }; const allDayNamesPolish: Record = { ...holidayNamesPolish, ...specialDayNamesPolish, }; ``` -------------------------------- ### Retrieve Icelandic Holidays with getHolidays Source: https://github.com/gaui/fridagar-node/blob/master/README.md Fetches a list of Icelandic public holidays and special days for a specific year or month. If no year is provided, it defaults to the current year. ```typescript import { getHolidays } from "fridagar"; const holidays2018 = getHolidays(2018); const holidaysInDecember2018 = getHolidays(2018, 12); const holidaysThisYear = getHolidays(); const holidaysInDecemberThisYear = getHolidays(undefined, 12); ``` -------------------------------- ### Retrieve All Days with getAllDays Source: https://github.com/gaui/fridagar-node/blob/master/README.md Returns a comprehensive list of official Icelandic public holidays for a specified year or month. This method is useful for generating full-year calendars. ```typescript import { getAllDays } from "fridagar"; const allDays2018 = getAllDays(2018); const allDaysInDecember2018 = getAllDays(2018, 12); const allDaysThisYear = getAllDays(); const allDaysInDecemberThisYear = getAllDays(undefined, 12); ``` -------------------------------- ### Define a SpecialDay object Source: https://github.com/gaui/fridagar-node/blob/master/README.md Demonstrates how to implement the SpecialDay interface. It includes a date, description, a stable key identifier, and a boolean flag indicating if it is a public holiday. ```typescript import type { SpecialDay } from "fridagar"; const sovereignDay2017: SpecialDay = { date: new Date("2017-12-01T00:00:00.000Z"), description: "Fullveldisdagurinn", key: "fullv", holiday: false, }; ``` -------------------------------- ### Define Holiday and SpecialDay types Source: https://context7.com/gaui/fridagar-node/llms.txt Illustrates the structure of Holiday and SpecialDay types used in the library, including their respective keys for identification and localization. ```typescript import type { Holiday, HolidayKey, SpecialDay, SpecialDayKey } from "fridagar"; const holiday: Holiday = { date: new Date("2024-12-24T00:00:00.000Z"), description: "Aðfangadagur", key: "adfanga", holiday: true, halfDay: true }; const specialDay: SpecialDay = { date: new Date("2024-02-12T00:00:00.000Z"), description: "Bolludagur", key: "bollu", holiday: false }; ``` -------------------------------- ### Retrieve Keyed Days with getAllDaysKeyed Source: https://github.com/gaui/fridagar-node/blob/master/README.md Returns an object where keys are stable identifiers for holidays and special days. This allows for easy access to specific days like Easter or Ash Wednesday. ```typescript import type { Holiday, SpecialDay } from "fridagar"; import { getAllDaysKeyed } from "fridagar"; const allDays1995 = getAllDaysKeyed(1995); const easter95: Holiday = allDays1995.paska; const ashWed95: SpecialDay = allDays1995.osku; console.log(easter95.date); console.log(easter95.description); ``` -------------------------------- ### Retrieve All Icelandic Holidays and Special Days Source: https://context7.com/gaui/fridagar-node/llms.txt Uses the getAllDays function to retrieve a comprehensive list of both official public holidays and cultural celebrations for a given year or month. ```typescript import { getAllDays } from "fridagar"; // Get all days (holidays + special days) for February 2024 const februaryDays = getAllDays(2024, 2); // Get all days for entire year const allDays2024 = getAllDays(2024); ``` -------------------------------- ### Retrieve Keyed Holidays and Special Days Source: https://context7.com/gaui/fridagar-node/llms.txt Retrieves all Icelandic holidays and special days for a given year, returned as an object indexed by a stable key. This allows for efficient direct access to specific days. ```typescript import type { Holiday, SpecialDay } from "fridagar"; import { getAllDaysKeyed } from "fridagar"; const allDays2024 = getAllDaysKeyed(2024); const easter: Holiday = allDays2024.paska; console.log(easter); const bolludagur: SpecialDay = allDays2024.bollu; console.log(bolludagur); const christmasEve = allDays2024.adfanga; console.log(`${christmasEve.description} is a half-day: ${christmasEve.halfDay}`); ``` -------------------------------- ### getAllDaysKeyed Source: https://context7.com/gaui/fridagar-node/llms.txt Retrieves all Icelandic public holidays and special days for a given year, returned as a keyed object for direct access. ```APIDOC ## getAllDaysKeyed ### Description Returns a keyed object with all Icelandic public holidays and special days for a given year, indexed by their stable `key` identifier. This is useful for direct access to specific days without array iteration. ### Method `getAllDaysKeyed(year: number): Record ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript import type { Holiday, SpecialDay } from "fridagar"; import { getAllDaysKeyed } from "fridagar"; const allDays2024 = getAllDaysKeyed(2024); // Access specific holidays by key (correctly typed as Holiday) const easter: Holiday = allDays2024.paska; console.log(easter); // { date: 2024-03-31T00:00:00.000Z, description: 'Páskadagur', key: 'paska', holiday: true } // Access special days by key (correctly typed as SpecialDay) const bolludagur: SpecialDay = allDays2024.bollu; console.log(bolludagur); // { date: 2024-02-12T00:00:00.000Z, description: 'Bolludagur', key: 'bollu', holiday: false } // Check Christmas Eve (half-day holiday) const christmasEve = allDays2024.adfanga; console.log(`${christmasEve.description} is a half-day: ${christmasEve.halfDay}`); // Aðfangadagur is a half-day: true ``` ### Response #### Success Response (200) - **Record** - An object where keys are day identifiers and values are Holiday or SpecialDay objects. #### Response Example ```json { "paska": { "date": "2024-03-31T00:00:00.000Z", "description": "Páskadagur", "key": "paska", "holiday": true }, "bollu": { "date": "2024-02-12T00:00:00.000Z", "description": "Bolludagur", "key": "bollu", "holiday": false }, "adfanga": { "date": "2024-12-24T00:00:00.000Z", "description": "Aðfangadagur", "key": "adfanga", "holiday": true, "halfDay": true } } ``` ``` -------------------------------- ### Retrieve Special Days with getOtherDays Source: https://github.com/gaui/fridagar-node/blob/master/README.md Fetches only unofficial, commonly celebrated special days that are typically considered workdays. Can be filtered by year and month. ```typescript import { getOtherDays } from "fridagar"; const otherdays2018 = getOtherDays(2018); const otherdaysInDecember2018 = getOtherDays(2018, 12); const otherdaysThisYear = getOtherDays(); const otherdaysInDecemberThisYear = getOtherDays(undefined, 12); ``` -------------------------------- ### getOtherDays Source: https://context7.com/gaui/fridagar-node/llms.txt Retrieves unofficial, commonly celebrated special days for a given year, optionally filtered by month. ```APIDOC ## getOtherDays ### Description Returns only unofficial, commonly celebrated special days (that are still workdays) for a given year, optionally filtered to a specific month. This excludes all official public holidays. ### Method `getOtherDays(year: number, month?: number): SpecialDay[] ### Parameters #### Path Parameters None #### Query Parameters - **year** (number) - Required - The year for which to retrieve special days. - **month** (number) - Optional - The month (1-12) to filter the results. If omitted, all months are included. #### Request Body None ### Request Example ```typescript import { getOtherDays } from "fridagar"; // Get all special (non-holiday) days for 2024 const specialDays2024 = getOtherDays(2024); console.log(specialDays2024.map(d => d.description)); // [ // 'Þrettándinn', 'Bóndadagur', 'Bolludagur', 'Sprengidagur', 'Öskudagur', // 'Valentínusardagur', 'Konudagur', 'Sjómannadagurinn', 'Sumarsólstöður', // 'Jónsmessa', 'Fyrsti vetrardagur', 'Hrekkjavaka', 'Dagur íslenskrar tungu', // 'Fullveldisdagurinn', 'Vetrarsólstöður', 'Þorláksmessa' // ] // Get special days for October 2024 const octoberSpecialDays = getOtherDays(2024, 10); console.log(octoberSpecialDays); // [ // { date: 2024-10-26T00:00:00.000Z, description: 'Fyrsti vetrardagur', key: 'vetur1', holiday: false }, // { date: 2024-10-31T00:00:00.000Z, description: 'Hrekkjavaka', key: 'hrekkja', holiday: false } // ] ``` ### Response #### Success Response (200) - **SpecialDay[]** - An array of SpecialDay objects. #### Response Example ```json [ { "date": "2024-10-26T00:00:00.000Z", "description": "Fyrsti vetrardagur", "key": "vetur1", "holiday": false }, { "date": "2024-10-31T00:00:00.000Z", "description": "Hrekkjavaka", "key": "hrekkja", "holiday": false } ] ``` ``` -------------------------------- ### isHoliday Source: https://context7.com/gaui/fridagar-node/llms.txt Checks if a given date is an official Icelandic public holiday. ```APIDOC ## isHoliday ### Description Checks if a given date is an official Icelandic public holiday and returns its info object if found, or `undefined` if the date is not a holiday. This only matches official holidays, not special days. ### Method `isHoliday(date: Date): Holiday | undefined ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript import { isHoliday } from "fridagar"; // Check Christmas Eve (a half-day holiday) const christmasEveCheck = isHoliday(new Date("2024-12-24")); console.log(christmasEveCheck); // { date: 2024-12-24T00:00:00.000Z, description: 'Aðfangadagur', key: 'adfanga', holiday: true, halfDay: true } // Check Þorláksmessa (NOT a holiday, just a special day) const thorlCheck = isHoliday(new Date("2024-12-23")); console.log(thorlCheck); // undefined // Check a regular day const regularDay = isHoliday(new Date("2024-07-15")); console.log(regularDay); // undefined // Practical usage: validate if office is closed function isOfficeClosed(date: Date): boolean { const holiday = isHoliday(date); if (!holiday) return false; // Office is fully closed on full holidays, but open in morning on half-days return !holiday.halfDay; } console.log(isOfficeClosed(new Date("2024-12-25"))); // true (Christmas Day) console.log(isOfficeClosed(new Date("2024-12-24"))); // false (half-day) ``` ### Response #### Success Response (200) - **Holiday | undefined** - The Holiday object if the date is an official holiday, otherwise `undefined`. #### Response Example ```json { "date": "2024-12-24T00:00:00.000Z", "description": "Aðfangadagur", "key": "adfanga", "holiday": true, "halfDay": true } ``` ``` -------------------------------- ### Check Inclusive Special Days Source: https://context7.com/gaui/fridagar-node/llms.txt Determines if a date is either an official public holiday or a special day. Useful for displaying greetings or event-specific logic. ```typescript import { isSpecialDay } from "fridagar"; const christmasEve = isSpecialDay(new Date("2024-12-24")); console.log(christmasEve); const thorlaksmessa = isSpecialDay(new Date("2024-12-23")); console.log(thorlaksmessa); function getGreeting(date: Date): string { const specialDay = isSpecialDay(date); if (specialDay) { return `Gleðilegan ${specialDay.description}!`; } return "Góðan daginn!"; } console.log(getGreeting(new Date("2024-02-12"))); ``` -------------------------------- ### Holiday Type Definition (TypeScript) Source: https://github.com/gaui/fridagar-node/blob/master/README.md Defines the structure of a `Holiday` object, which represents an Icelandic public holiday. Each object includes the date, a description, a stable key identifier, and flags indicating if it's a full holiday and if it's a half-day holiday. All dates are standardized to 00:00:00 UTC. ```typescript import type { Holiday } from "fridagar"; // Example const xmasEve2017: Holiday = { date: new Date("2017-12-24T00:00:00.000Z"), description: "Aðfangadagur", key: "adfanga", // stable identifier for this holiday holiday: true, halfDay: true, // Aðfangadagur is not a holiday in the moening. }; ``` -------------------------------- ### Retrieve Official Icelandic Holidays Source: https://context7.com/gaui/fridagar-node/llms.txt Uses the getHolidays function to fetch official non-working days for a specific year or month. It excludes cultural special days that are not classified as official holidays. ```typescript import { getHolidays } from "fridagar"; // Get all holidays for 2024 const holidays2024 = getHolidays(2024); // Get holidays for December 2024 only const decemberHolidays = getHolidays(2024, 12); // Get holidays for current year const holidaysThisYear = getHolidays(); ``` -------------------------------- ### Calculate Workdays Relative to a Reference Date (TypeScript) Source: https://github.com/gaui/fridagar-node/blob/master/README.md The `workdaysFromDate` function calculates a future or past date based on a specified number of workdays from a reference date. It can optionally include or exclude half-day holidays from the workday count. If no reference date is provided, it defaults to the current date. The returned date is always set to 00:00:00 UTC. ```typescript import { workdaysFromDate } from "fridagar"; const dec23th2018 = new Date("2018-12-23"); // Thursday const jan1st2024 = new Date("2024-01-01"); // Tuesday // Treats Aðfangadagur as a non-work day by default const secondWorkDay = workdaysFromDate(2, dec23th2018); // new Date('2021-12-28') // Tuesday // Optionally treats Aðfangadagur as a work day const secondWorkDayInclHalfDay = workdaysFromDate(2, dec23th2018, true); // new Date('2021-12-27') // Monday // One business days before New Year's day of 2024 const prevDay = workdaysFromDate(-1, jan1st2024); // new Date('2023-12-29') // Friday ``` ```typescript const thirdWorkDayFromToday = workdaysFromDate(3); ``` -------------------------------- ### Validate Holiday Status with isHoliday Source: https://github.com/gaui/fridagar-node/blob/master/README.md Checks if a provided Date object corresponds to an Icelandic public holiday. Returns the holiday object if found, otherwise returns undefined. ```typescript import { isHoliday } from "fridagar"; const res1 = isHoliday(new Date("2018-12-24")); console.log(res1); const res2 = isHoliday(new Date("2018-12-23")); console.log(res2); ``` -------------------------------- ### Check if a Date is a Special Icelandic Day (TypeScript) Source: https://github.com/gaui/fridagar-node/blob/master/README.md The `isSpecialDay` function checks if a given date falls on an Icelandic public holiday or a recognized special day. It returns an object containing information about the day if it's special, otherwise it returns undefined. This function is useful for applications needing to identify and handle specific Icelandic dates. ```typescript import { isSpecialDay } from "fridagar"; const res1 = isSpecialDay(new Date("2018-12-24")); console.log(res1); // Logs the `Holiday` object for Aðfangadagur const res2 = isSpecialDay(new Date("2018-12-23")); console.log(res2); // Logs the `SpecialDay` object for Þorláksmessa const res3 = isSpecialDay(new Date("2018-12-19")); console.log(res3); // Logs `undefined` (Because Dec. 19th is just a normal day.) ``` -------------------------------- ### Filter Unofficial Special Days Source: https://context7.com/gaui/fridagar-node/llms.txt Fetches a list of commonly celebrated special days that are not official public holidays. Supports optional filtering by month. ```typescript import { getOtherDays } from "fridagar"; const specialDays2024 = getOtherDays(2024); console.log(specialDays2024.map(d => d.description)); const octoberSpecialDays = getOtherDays(2024, 10); console.log(octoberSpecialDays); ``` -------------------------------- ### isSpecialDay Source: https://context7.com/gaui/fridagar-node/llms.txt Checks if a given date is an official holiday or a commonly celebrated special day. ```APIDOC ## isSpecialDay ### Description Checks if a given date is either an official Icelandic public holiday OR a commonly celebrated special day, and returns its info object if found. This is more inclusive than `isHoliday`. ### Method `isSpecialDay(date: Date): Holiday | SpecialDay | undefined ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript import { isSpecialDay } from "fridagar"; // Check Christmas Eve (a holiday) const christmasEve = isSpecialDay(new Date("2024-12-24")); console.log(christmasEve); // { date: 2024-12-24T00:00:00.000Z, description: 'Aðfangadagur', key: 'adfanga', holiday: true, halfDay: true } // Check Þorláksmessa (a special day, but NOT a holiday) const thorlaksmessa = isSpecialDay(new Date("2024-12-23")); console.log(thorlaksmessa); // { date: 2024-12-23T00:00:00.000Z, description: 'Þorláksmessa', key: 'thorl', holiday: false } // Check a regular day const regularDay = isSpecialDay(new Date("2024-07-15")); console.log(regularDay); // undefined // Practical usage: display special greetings function getGreeting(date: Date): string { const specialDay = isSpecialDay(date); if (specialDay) { return `Gleðilegan ${specialDay.description}!`; } return "Góðan daginn!"; } console.log(getGreeting(new Date("2024-02-12"))); // Gleðilegan Bolludagur! console.log(getGreeting(new Date("2024-07-15"))); // Góðan daginn! ``` ### Response #### Success Response (200) - **Holiday | SpecialDay | undefined** - The Holiday or SpecialDay object if the date matches, otherwise `undefined`. #### Response Example ```json { "date": "2024-12-23T00:00:00.000Z", "description": "Þorláksmessa", "key": "thorl", "holiday": false } ``` ``` -------------------------------- ### Validate Official Public Holidays Source: https://context7.com/gaui/fridagar-node/llms.txt Checks if a specific date is an official public holiday. Returns the holiday object if found, or undefined otherwise. ```typescript import { isHoliday } from "fridagar"; const christmasEveCheck = isHoliday(new Date("2024-12-24")); console.log(christmasEveCheck); function isOfficeClosed(date: Date): boolean { const holiday = isHoliday(date); if (!holiday) return false; return !holiday.halfDay; } console.log(isOfficeClosed(new Date("2024-12-25"))); console.log(isOfficeClosed(new Date("2024-12-24"))); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.