us-holidays
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -10,2 +10,3 @@ export declare class Holiday { | ||
static washingtonsBirthday: Holiday; | ||
static goodFriday: Holiday; | ||
static memorialDay: Holiday; | ||
@@ -12,0 +13,0 @@ static juneteenthNationalIndependenceDay: Holiday; |
@@ -19,2 +19,3 @@ "use strict"; | ||
Holidays.washingtonsBirthday = new Holiday("Washington's Birthday", function (year) { return new year_1.default(year).washingtonsBirthday; }); | ||
Holidays.goodFriday = new Holiday('Good Friday', function (year) { return new year_1.default(year).goodFriday; }); | ||
Holidays.memorialDay = new Holiday('Memorial Day', function (year) { return new year_1.default(year).memorialDay; }); | ||
@@ -32,2 +33,3 @@ Holidays.juneteenthNationalIndependenceDay = new Holiday('Juneteenth National Independence Day', function (year) { return new year_1.default(year).juneteenthNationalIndependenceDay; }); | ||
Holidays.washingtonsBirthday, | ||
Holidays.goodFriday, | ||
Holidays.memorialDay, | ||
@@ -34,0 +36,0 @@ Holidays.juneteenthNationalIndependenceDay, |
{ | ||
"name": "us-holidays", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"license": "MIT", | ||
@@ -11,5 +11,6 @@ "main": "index.js", | ||
"postpublish": "rm index.js index.d.ts year.js year.d.ts", | ||
"test": "tsx -r dotenv-override-true/config src/index.ts" | ||
"test": "jest -w 1 test/$t" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^29.5.12", | ||
"@types/node": "^20.14.12", | ||
@@ -23,4 +24,7 @@ "@typescript-eslint/eslint-plugin": "^7.17.0", | ||
"eslint-plugin-prettier": "^5.2.1", | ||
"jest": "^29.7.0", | ||
"prettier": "^3.3.3", | ||
"sort-package-json": "^2.10.0", | ||
"ts-jest": "^29.2.3", | ||
"ts-node": "^10.9.2", | ||
"tsx": "^4.16.2", | ||
@@ -27,0 +31,0 @@ "ttpt": "^0.9.6", |
@@ -5,4 +5,12 @@ # United States Holidays | ||
Currently on federal holdays are supported. | ||
Currently 11 federal holidays are supported. | ||
Good Friday is also supported. | ||
## Install | ||
``` | ||
yarn add us-holidays | ||
``` | ||
## Usage | ||
@@ -9,0 +17,0 @@ |
@@ -23,2 +23,3 @@ import Year from './year'; | ||
); | ||
public static goodFriday = new Holiday('Good Friday', (year: number) => new Year(year).goodFriday); | ||
public static memorialDay = new Holiday('Memorial Day', (year: number) => new Year(year).memorialDay); | ||
@@ -40,2 +41,3 @@ public static juneteenthNationalIndependenceDay = new Holiday( | ||
Holidays.washingtonsBirthday, | ||
Holidays.goodFriday, | ||
Holidays.memorialDay, | ||
@@ -42,0 +44,0 @@ Holidays.juneteenthNationalIndependenceDay, |
@@ -36,2 +36,26 @@ class Year { | ||
// not a federal holiday | ||
// but stock market is closed | ||
// code generated by ChatGPT | ||
public get goodFriday() { | ||
const a = this.year % 19; | ||
const b = Math.floor(this.year / 100); | ||
const c = this.year % 100; | ||
const d = Math.floor(b / 4); | ||
const e = b % 4; | ||
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; | ||
const easterSunday = new Date(this.year, month - 1, day); | ||
const goodFriday = new Date(easterSunday); | ||
goodFriday.setDate(easterSunday.getDate() - 2); // Good Friday is 2 days before Easter Sunday | ||
return goodFriday.toISOString().slice(0, 10); | ||
} | ||
// last Monday in May | ||
@@ -38,0 +62,0 @@ // should be either 4th or 5th Monday |
@@ -8,2 +8,3 @@ declare class Year { | ||
get washingtonsBirthday(): string; | ||
get goodFriday(): string; | ||
get memorialDay(): string; | ||
@@ -10,0 +11,0 @@ get juneteenthNationalIndependenceDay(): string; |
27
year.js
@@ -44,2 +44,29 @@ "use strict"; | ||
}); | ||
Object.defineProperty(Year.prototype, "goodFriday", { | ||
// not a federal holiday | ||
// but stock market is closed | ||
// code generated by ChatGPT | ||
get: function () { | ||
var a = this.year % 19; | ||
var b = Math.floor(this.year / 100); | ||
var c = this.year % 100; | ||
var d = Math.floor(b / 4); | ||
var e = b % 4; | ||
var f = Math.floor((b + 8) / 25); | ||
var g = Math.floor((b - f + 1) / 3); | ||
var h = (19 * a + b - d - g + 15) % 30; | ||
var i = Math.floor(c / 4); | ||
var k = c % 4; | ||
var l = (32 + 2 * e + 2 * i - h - k) % 7; | ||
var m = Math.floor((a + 11 * h + 22 * l) / 451); | ||
var month = Math.floor((h + l - 7 * m + 114) / 31); | ||
var day = ((h + l - 7 * m + 114) % 31) + 1; | ||
var easterSunday = new Date(this.year, month - 1, day); | ||
var goodFriday = new Date(easterSunday); | ||
goodFriday.setDate(easterSunday.getDate() - 2); // Good Friday is 2 days before Easter Sunday | ||
return goodFriday.toISOString().slice(0, 10); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Year.prototype, "memorialDay", { | ||
@@ -46,0 +73,0 @@ // last Monday in May |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19125
16
437
36
18