@qntm-code/utils
Version:
A collection of useful utility functions with associated TypeScript types. All functions have been unit tested.
28 lines (27 loc) • 1.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const src_1 = require("../../../src");
const date_modifiers_test_suites_1 = require("./date-modifiers-test-suites");
describe(`addToDate`, () => {
it(`should not overwrite the provided date`, () => {
const date = new Date(2023, 2, 27, 0, 0, 0, 0);
const original = new Date(date.getTime());
(0, src_1.addToDate)(date, 1, src_1.TimeUnit.Millisecond);
expect(date).toEqual(original);
});
(0, date_modifiers_test_suites_1.generateDateModifierTestSuites)(src_1.addToDate, 'add', 'to');
describe(`Docs BST examples`, () => {
it('Adding a month will add the specified number of months to the date.', () => {
const date = new Date('2023-02-28T00:00:00.000');
expect((0, src_1.addToDate)(date, 1, src_1.TimeUnit.Month)).toEqual(new Date('2023-03-28T00:00:00.000'));
});
it(`Should maintain hour when crossing into daylight savings time`, () => {
const date = new Date('2023-03-25T06:00:00.000');
expect((0, src_1.addToDate)(date, 1, src_1.TimeUnit.Day).getHours()).toEqual(6);
});
it(`Adding hours, minutes, seconds, or milliseconds, should result in a different hour`, () => {
const date = new Date('2023-03-25T06:00:00.000');
expect((0, src_1.addToDate)(date, 24, src_1.TimeUnit.Hours).getHours()).toEqual(7);
});
});
});