-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7915a56
commit 5068cfb
Showing
247 changed files
with
3,157 additions
and
5,115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 1,12 @@ | ||
/* eslint-env mocha */ | ||
|
||
import assert from "node:assert"; | ||
import { describe, it, expect } from "vitest"; | ||
import { describe, expect, it } from "vitest"; | ||
import { addLeadingZeros } from "./index.js"; | ||
|
||
describe("addLeadingZeros", () => { | ||
it("adds leading zeros when number has fewer digits than target length", () => { | ||
expect(addLeadingZeros(7, 3)).toBe("007"); | ||
assert.strictEqual(addLeadingZeros(7, 2), "07"); | ||
assert.strictEqual(addLeadingZeros(7, 1), "7"); | ||
assert.strictEqual(addLeadingZeros(7, 0), "7"); | ||
assert.strictEqual(addLeadingZeros(7, -1), "7"); | ||
expect(addLeadingZeros(7, 2)).toBe("07"); | ||
expect(addLeadingZeros(7, 1)).toBe("7"); | ||
expect(addLeadingZeros(7, 0)).toBe("7"); | ||
expect(addLeadingZeros(7, -1)).toBe("7"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 1,25 @@ | ||
/* eslint-env mocha */ | ||
|
||
import assert from "node:assert"; | ||
import { describe, it } from "vitest"; | ||
import { describe, expect, it } from "vitest"; | ||
import { getTimezoneOffsetInMilliseconds } from "./index.js"; | ||
|
||
describe("getTimezoneOffsetInMilliseconds", () => { | ||
it("works for a modern date", () => { | ||
const date = new Date(2018, 0 /* Jan */, 1, 12, 34, 56, 789); | ||
const result = date.getTime() - getTimezoneOffsetInMilliseconds(date); | ||
const expectedResult = Date.UTC(2018, 0 /* Jan */, 1, 12, 34, 56, 789); | ||
assert(result === expectedResult); | ||
expect(result).toBe(expectedResult); | ||
}); | ||
|
||
it("works for a date before standardized timezones", () => { | ||
const date = new Date(1800, 0 /* Jan */, 1, 12, 34, 56, 789); | ||
const result = date.getTime() - getTimezoneOffsetInMilliseconds(date); | ||
const expectedResult = Date.UTC(1800, 0 /* Jan */, 1, 12, 34, 56, 789); | ||
assert(result === expectedResult); | ||
expect(result).toBe(expectedResult); | ||
}); | ||
|
||
it("works for a date BC", () => { | ||
const date = new Date(-500, 0 /* Jan */, 1, 12, 34, 56, 789); | ||
const result = date.getTime() - getTimezoneOffsetInMilliseconds(date); | ||
const expectedResult = Date.UTC(-500, 0 /* Jan */, 1, 12, 34, 56, 789); | ||
assert(result === expectedResult); | ||
expect(result).toBe(expectedResult); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 1,75 @@ | ||
/* eslint-env mocha */ | ||
|
||
import assert from "node:assert"; | ||
import { describe, it } from "vitest"; | ||
import { describe, expect, it } from "vitest"; | ||
import { addBusinessDays } from "./index.js"; | ||
|
||
describe("addBusinessDays", () => { | ||
it("adds the given number of business days", () => { | ||
const result = addBusinessDays(new Date(2014, 8 /* Sep */, 1), 10); | ||
assert.deepStrictEqual(result, new Date(2014, 8 /* Sep */, 15)); | ||
expect(result).toEqual(new Date(2014, 8 /* Sep */, 15)); | ||
}); | ||
|
||
it("handles negative amount", () => { | ||
const result = addBusinessDays(new Date(2014, 8 /* Sep */, 15), -10); | ||
assert.deepStrictEqual(result, new Date(2014, 8 /* Sep */, 1)); | ||
expect(result).toEqual(new Date(2014, 8 /* Sep */, 1)); | ||
}); | ||
|
||
it("returns the Monday when 1 day is added on the Friday", () => { | ||
assert.deepStrictEqual( | ||
addBusinessDays(new Date(2020, 0 /* Jan */, 10), 1), // Friday | ||
new Date(2020, 0 /* Jan */, 13), // Monday | ||
); | ||
expect(addBusinessDays(new Date(2020, 0 /* Jan */, 10), 1)).toEqual(// Friday | ||
// Monday | ||
new Date(2020, 0 /* Jan */, 13)); | ||
}); | ||
|
||
it("returns the Monday when 1 day is added on the Satuday", () => { | ||
assert.deepStrictEqual( | ||
addBusinessDays(new Date(2020, 0 /* Jan */, 11), 1), // Saturday | ||
new Date(2020, 0 /* Jan */, 13), // Monday | ||
); | ||
expect(addBusinessDays(new Date(2020, 0 /* Jan */, 11), 1)).toEqual(// Saturday | ||
// Monday | ||
new Date(2020, 0 /* Jan */, 13)); | ||
}); | ||
|
||
it("returns the Monday when 1 day is added on the Sunday", () => { | ||
assert.deepStrictEqual( | ||
addBusinessDays(new Date(2020, 0 /* Jan */, 12), 1), // Sunday | ||
new Date(2020, 0 /* Jan */, 13), // Monday | ||
); | ||
expect(addBusinessDays(new Date(2020, 0 /* Jan */, 12), 1)).toEqual(// Sunday | ||
// Monday | ||
new Date(2020, 0 /* Jan */, 13)); | ||
}); | ||
|
||
it("can handle a large number of business days", () => { | ||
const result = addBusinessDays(new Date(2014, 0 /* Jan */, 1), 3387885); | ||
assert.deepStrictEqual(result, new Date(15000, 0 /* Jan */, 1)); | ||
expect(result).toEqual(new Date(15000, 0 /* Jan */, 1)); | ||
}); | ||
|
||
it("accepts a timestamp", () => { | ||
const result = addBusinessDays( | ||
new Date(2014, 8 /* Sep */, 1).getTime(), | ||
10, | ||
); | ||
assert.deepStrictEqual(result, new Date(2014, 8 /* Sep */, 15)); | ||
expect(result).toEqual(new Date(2014, 8 /* Sep */, 15)); | ||
}); | ||
|
||
it("does not mutate the original date", () => { | ||
const date = new Date(2014, 8 /* Sep */, 1); | ||
addBusinessDays(date, 11); | ||
assert.deepStrictEqual(date, new Date(2014, 8 /* Sep */, 1)); | ||
expect(date).toEqual(new Date(2014, 8 /* Sep */, 1)); | ||
}); | ||
|
||
it("returns `Invalid Date` if the given date is invalid", () => { | ||
const result = addBusinessDays(new Date(NaN), 10); | ||
assert(result instanceof Date && isNaN(result.getTime())); | ||
expect(result instanceof Date && isNaN(result.getTime())).toBe(true); | ||
}); | ||
|
||
it("returns `Invalid Date` if the given amount is NaN", () => { | ||
const result = addBusinessDays(new Date(2014, 8 /* Sep */, 1), NaN); | ||
assert(result instanceof Date && isNaN(result.getTime())); | ||
expect(result instanceof Date && isNaN(result.getTime())).toBe(true); | ||
}); | ||
|
||
it("starting from a weekend day should land on a weekday when reducing a divisible by 5", () => { | ||
const substractResult = addBusinessDays(new Date(2019, 7, 18), -5); | ||
assert.deepStrictEqual(substractResult, new Date(2019, 7, 12)); | ||
expect(substractResult).toEqual(new Date(2019, 7, 12)); | ||
|
||
const subtractResultWeekend = addBusinessDays(new Date(2019, 7, 17), -5); | ||
assert.deepStrictEqual(subtractResultWeekend, new Date(2019, 7, 12)); | ||
expect(subtractResultWeekend).toEqual(new Date(2019, 7, 12)); | ||
|
||
const addResult = addBusinessDays(new Date(2019, 7, 18), 5); | ||
assert.deepStrictEqual(addResult, new Date(2019, 7, 23)); | ||
expect(addResult).toEqual(new Date(2019, 7, 23)); | ||
|
||
const addResultWeekend = addBusinessDays(new Date(2019, 7, 17), 5); | ||
assert.deepStrictEqual(addResultWeekend, new Date(2019, 7, 23)); | ||
expect(addResultWeekend).toEqual(new Date(2019, 7, 23)); | ||
}); | ||
}); |
Oops, something went wrong.