UNPKG

black-friday

Version:

A lightweight, dependency-free utility to calculate Thanksgiving, Black Friday, and Cyber Monday dates for a given year.

44 lines 1.91 kB
// src/index.ts var getNovFirst = (year = (/* @__PURE__ */ new Date()).getFullYear()) => new Date(year, 10, 1); var getFirstThursday = (year = (/* @__PURE__ */ new Date()).getFullYear()) => { const novFirst = getNovFirst(year); const dayOfWeek = novFirst.getDay(); const daysToAdd = dayOfWeek <= 4 ? 4 - dayOfWeek : 11 - dayOfWeek; return new Date(novFirst.getFullYear(), novFirst.getMonth(), novFirst.getDate() + daysToAdd); }; var thanksgiving = (year = (/* @__PURE__ */ new Date()).getFullYear()) => { const firstThursday = getFirstThursday(year); return new Date(firstThursday.getFullYear(), firstThursday.getMonth(), firstThursday.getDate() + 21); }; var blackFriday = (year = (/* @__PURE__ */ new Date()).getFullYear()) => { const thanksgivingDate = thanksgiving(year); return new Date(thanksgivingDate.getFullYear(), thanksgivingDate.getMonth(), thanksgivingDate.getDate() + 1); }; var cyberMonday = (year = (/* @__PURE__ */ new Date()).getFullYear()) => { const thanksgivingDate = thanksgiving(year); return new Date(thanksgivingDate.getFullYear(), thanksgivingDate.getMonth(), thanksgivingDate.getDate() + 4); }; var daysUntil = (eventDate) => { const today = /* @__PURE__ */ new Date(); today.setHours(0, 0, 0, 0); eventDate.setHours(0, 0, 0, 0); return Math.ceil((eventDate.getTime() - today.getTime()) / (1e3 * 3600 * 24)); }; var daysUntilThanksgiving = (year = (/* @__PURE__ */ new Date()).getFullYear()) => { return daysUntil(thanksgiving(year)); }; var daysUntilBlackFriday = (year = (/* @__PURE__ */ new Date()).getFullYear()) => { return daysUntil(blackFriday(year)); }; var daysUntilCyberMonday = (year = (/* @__PURE__ */ new Date()).getFullYear()) => { return daysUntil(cyberMonday(year)); }; export { blackFriday, cyberMonday, daysUntilBlackFriday, daysUntilCyberMonday, daysUntilThanksgiving, thanksgiving }; //# sourceMappingURL=index.mjs.map