diff --git a/src/utils/lock-helper.ts b/src/utils/lock-helper.ts index 288b492d9..35ea843d0 100644 --- a/src/utils/lock-helper.ts +++ b/src/utils/lock-helper.ts @@ -2,6 +2,10 @@ export function timestampNMinutesFromNow(numberOfMinutes: number) { return new Date(Date.now() + numberOfMinutes * 60000).toUTCString(); } +export function timestampNSecondsFromNow(numberOfSeconds: number) { + return new Date(Date.now() + numberOfSeconds * 1000).toUTCString(); +} + export function isLocked(maybeLockTimestamp?: string) { return ( maybeLockTimestamp && diff --git a/test/unit/utils/lock-helper.test.ts b/test/unit/utils/lock-helper.test.ts index 7ff888844..a3e6ee9aa 100644 --- a/test/unit/utils/lock-helper.test.ts +++ b/test/unit/utils/lock-helper.test.ts @@ -3,6 +3,7 @@ import { describe } from "mocha"; import { isLocked, timestampNMinutesFromNow, + timestampNSecondsFromNow, } from "../../../src/utils/lock-helper"; import sinon from "sinon"; describe("lockout-helper", () => { @@ -40,6 +41,27 @@ describe("lockout-helper", () => { }); }); + describe("timestampNSecondsFromNow", () => { + it("should return the correct timestamp from the current datetime", () => { + const TEST_SCENARIO_PARAMS = [ + { + numberOfSeconds: 60, + expectedTimestamp: "Thu, 01 Feb 2024 00:01:00 GMT", + }, + { + numberOfSeconds: 1, + expectedTimestamp: "Thu, 01 Feb 2024 00:00:01 GMT", + }, + ]; + + TEST_SCENARIO_PARAMS.forEach((params) => { + expect(timestampNSecondsFromNow(params.numberOfSeconds)).to.eq( + params.expectedTimestamp + ); + }); + }); + }); + describe("checkIfLocked", () => { it("should correctly determine if a user is locked", () => { const TEST_SCENARIO_PARAMS = [