diff --git a/packages/util/index.js b/packages/util/index.js index 37b2289c5..a01cbad7e 100644 --- a/packages/util/index.js +++ b/packages/util/index.js @@ -5,8 +5,6 @@ export { formatZonedToLocalDate, formatLocalToZonedDate, getDate, - getTimeZoneDesignator, - getTimeZoneOffset, isDate, } from "./lib/date.js"; export { sanitise } from "./lib/object.js"; diff --git a/packages/util/lib/date.js b/packages/util/lib/date.js index 704fc45a9..8a70893ac 100644 --- a/packages/util/lib/date.js +++ b/packages/util/lib/date.js @@ -1,4 +1,4 @@ -import { tz, tzOffset } from "@date-fns/tz"; +import { tz } from "@date-fns/tz"; import { format, parseISO } from "date-fns"; import * as locales from "date-fns/locale"; @@ -124,50 +124,6 @@ export const getDate = (setting, dateString = "") => { return formattedDateTime; }; -/** - * Get local time zone offset in hours and minutes - * @param {number} [minutes] - Time zone offset in minutes - * @returns {string} Local time zone designator, i.e. +05:30, -06:00 or Z - */ -export const getTimeZoneDesignator = (minutes) => { - minutes = minutes || minutes === 0 ? minutes : new Date().getTimezoneOffset(); - const hours = Math.abs(minutes / 60).toString(); - - const offsetHours = Number.parseInt(hours, 10); - const offsetMinutes = Math.abs(minutes % 60); - - const hh = String(offsetHours).padStart(2, "0"); - const mm = String(offsetMinutes).padStart(2, "0"); - - // Prepend positive/negative symbol to designator - // If offset minutes is 0, time zone is UTC, so use Z - let designator; - if (minutes < 0) { - designator = `+${hh}:${mm}`; - } else if (minutes > 0) { - designator = `-${hh}:${mm}`; - } else if (minutes === 0) { - designator = "+00:00"; - } - - return designator; -}; - -/** - * Get offset minutes from time zone name - * @param {string} timeZone - IANA tz timezone - * @param {Date} date - Date time - * @returns {number} Minutes offset from UTC - */ -export const getTimeZoneOffset = (timeZone, date) => { - const minutes = tzOffset(timeZone, date); - - // Ensure `tzOffset()` returns same value as - // `Date.prototype.getTimezoneOffset()` - const offset = minutes === 0 ? 0 : minutes * -1; - return offset; -}; - /** * Check if a string can be parsed as a date * @param {string} string - String diff --git a/packages/util/test/unit/date.js b/packages/util/test/unit/date.js index 559c664f5..1e45bee70 100644 --- a/packages/util/test/unit/date.js +++ b/packages/util/test/unit/date.js @@ -8,8 +8,6 @@ import { formatZonedToLocalDate, formatLocalToZonedDate, getDate, - getTimeZoneDesignator, - getTimeZoneOffset, isDate, } from "../../lib/date.js"; @@ -199,30 +197,6 @@ describe("util/lib/date", () => { assert.equal(result, "2020-01-02T16:00:00.000Z"); }); - it("Gets server timezone offset from minutes", () => { - assert.equal(getTimeZoneDesignator(0), "+00:00"); - assert.equal(getTimeZoneDesignator(150), "-02:30"); - assert.equal(getTimeZoneDesignator(-300), "+05:00"); - }); - - it("Gets server timezone offset from local time", () => { - process.env.TZ = "Asia/Taipei"; // Does not observe DST - assert.equal(getTimeZoneDesignator(), "+08:00"); - - process.env.TZ = "America/Panama"; // Does not observe DST - assert.equal(getTimeZoneDesignator(), "-05:00"); - - process.env.TZ = "UTC"; - assert.equal(getTimeZoneDesignator(), "+00:00"); - }); - - it("Gets offset minutes from time zone name", () => { - const date = new Date(); - assert.equal(getTimeZoneOffset("Asia/Taipei", date), -480); - assert.equal(getTimeZoneOffset("America/Panama", date), 300); - assert.equal(getTimeZoneOffset("UTC", date), 0); - }); - it("Check if a string can be parsed as a date", () => { assert.equal(isDate("2024-02-14T13:24:00+0100"), true); assert.equal(isDate("Wed Feb 14 2024 13:24:00 GMT+0100"), true);