From 6996a8d83bb6fef14a57b11f37bb881fe296ac96 Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Mon, 9 Dec 2024 13:45:32 -0500 Subject: [PATCH] Force a consistent non-UTC timezone for tests, so we can validate outputs. Minor cleanup. --- client/src/utils/dates.test.ts | 2 +- client/src/utils/dates.ts | 4 ++-- client/tests/jest/jest.setup.js | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/client/src/utils/dates.test.ts b/client/src/utils/dates.test.ts index be2ee28c06eb..02583c03258e 100644 --- a/client/src/utils/dates.test.ts +++ b/client/src/utils/dates.test.ts @@ -38,4 +38,4 @@ describe("dates.ts", () => { expect(formatted).toBe("Sunday Oct 1st 8:00:00 2023 GMT-4"); }); }); -}); \ No newline at end of file +}); diff --git a/client/src/utils/dates.ts b/client/src/utils/dates.ts index e89cc7829811..7903a56561b5 100644 --- a/client/src/utils/dates.ts +++ b/client/src/utils/dates.ts @@ -20,7 +20,7 @@ export function galaxyTimeToDate(galaxyTime: string): Date { } /** - * Formats a UTC Date object into a human-readable string. + * Formats a UTC Date object into a human-readable string, localized to the user's time zone. * @param {Date} utcDate - The UTC Date object. * @returns {string} The formatted date string. */ @@ -29,7 +29,7 @@ export function localizeUTCPretty(utcDate: Date): string { } /** - * Converts a Galaxy time string to a human-readable formatted date string. + * Converts a Galaxy time string to a human-readable formatted date string, localized to the user's time zone. * @param {string} galaxyTime - The Galaxy time string in ISO format. * @returns {string} The formatted date string. */ diff --git a/client/tests/jest/jest.setup.js b/client/tests/jest/jest.setup.js index 505e186fd517..eb1f67ae1833 100644 --- a/client/tests/jest/jest.setup.js +++ b/client/tests/jest/jest.setup.js @@ -12,6 +12,9 @@ Vue.config.devtools = false; and this makes the tag tests work correctly */ global.setImmediate = global.setTimeout; +// Consistent timezone for tests so we can compare date strings +process.env.TZ = "America/New_York"; + // Always mock the following imports jest.mock("@/composables/hashedUserId"); jest.mock("@/composables/userLocalStorage");