diff --git a/packages/datetime/package.json b/packages/datetime/package.json index 58967d54c6..8cec740563 100644 --- a/packages/datetime/package.json +++ b/packages/datetime/package.json @@ -46,7 +46,6 @@ "classnames": "^2.3.1", "date-fns": "^2.28.0", "date-fns-tz": "^2.0.0", - "lodash": "^4.17.21", "react-day-picker": "7.4.9", "tslib": "~2.6.2" }, @@ -65,7 +64,6 @@ "@blueprintjs/karma-build-scripts": "workspace:^", "@blueprintjs/node-build-scripts": "workspace:^", "@blueprintjs/test-commons": "workspace:^", - "@types/lodash": "~4.14.202", "enzyme": "^3.11.0", "karma": "^6.4.2", "mocha": "^10.2.0", diff --git a/packages/datetime/src/common/getTimezone.ts b/packages/datetime/src/common/getTimezone.ts index bc92995d12..b628b59475 100644 --- a/packages/datetime/src/common/getTimezone.ts +++ b/packages/datetime/src/common/getTimezone.ts @@ -14,22 +14,23 @@ * limitations under the License. */ -import memoize from "lodash/memoize"; - import { UTC_TIME } from "./timezoneItems"; /** - * Gets the users current time zone, for example "Europe/Oslo". - * This is currently backed by the browser or computer's locale setting. + * Keep the returned timezone constant for a page load. */ -export const getCurrentTimezone: () => string = memoize(guessTimezone); +let memoizedTimezone: string | null = null; /** - * Unsupported in IE, which newer Blueprint components do not support. - * In the unlikely case that the browser API returns undefined, we default to UTC. - * - * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions + * Gets the users current time zone, for example "Europe/Oslo". + * This is currently backed by the browser or computer's locale setting. */ -function guessTimezone(): string { - return Intl.DateTimeFormat().resolvedOptions().timeZone ?? UTC_TIME.ianaCode; +export function getCurrentTimezone(): string { + if (memoizedTimezone === null) { + // Unsupported in IE, which newer Blueprint components do not support. + // In the unlikely case that the browser API returns undefined, we default to UTC. + // @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions + memoizedTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone ?? UTC_TIME.ianaCode; + } + return memoizedTimezone; } diff --git a/packages/datetime/src/common/timezoneUtils.ts b/packages/datetime/src/common/timezoneUtils.ts index b221923fc9..d75bbb4a83 100644 --- a/packages/datetime/src/common/timezoneUtils.ts +++ b/packages/datetime/src/common/timezoneUtils.ts @@ -15,7 +15,6 @@ */ import { formatInTimeZone, utcToZonedTime, zonedTimeToUtc } from "date-fns-tz"; -import isEmpty from "lodash/isEmpty"; import { getCurrentTimezone } from "./getTimezone"; import { TimePrecision } from "./timePrecision"; @@ -69,7 +68,9 @@ export function getDateObjectFromIsoString( if (value === undefined) { return undefined; } - if (value === null || isEmpty(value)) { + // This function previously used lodash.isEmpty to check for empty values, which returns true for e.g. numbers and Dates. + // Be extra defensive and avoid breakage in case a consumer is incorrectly passing in such a value. + if (value === null || value === "" || typeof value !== "string") { return null; } const date = new Date(value); diff --git a/packages/datetime2/package.json b/packages/datetime2/package.json index 9b061cabb5..1a39bf6fbd 100644 --- a/packages/datetime2/package.json +++ b/packages/datetime2/package.json @@ -61,7 +61,6 @@ "@blueprintjs/karma-build-scripts": "workspace:^", "@blueprintjs/node-build-scripts": "workspace:^", "@blueprintjs/test-commons": "workspace:^", - "@types/lodash": "~4.14.202", "enzyme": "^3.11.0", "karma": "^6.4.2", "mocha": "^10.2.0", diff --git a/yarn.lock b/yarn.lock index aa55fab869..b622691cc1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -496,7 +496,6 @@ __metadata: "@blueprintjs/karma-build-scripts": "workspace:^" "@blueprintjs/node-build-scripts": "workspace:^" "@blueprintjs/test-commons": "workspace:^" - "@types/lodash": "npm:~4.14.202" classnames: "npm:^2.3.1" date-fns: "npm:^2.28.0" enzyme: "npm:^3.11.0" @@ -531,13 +530,11 @@ __metadata: "@blueprintjs/node-build-scripts": "workspace:^" "@blueprintjs/select": "workspace:^" "@blueprintjs/test-commons": "workspace:^" - "@types/lodash": "npm:~4.14.202" classnames: "npm:^2.3.1" date-fns: "npm:^2.28.0" date-fns-tz: "npm:^2.0.0" enzyme: "npm:^3.11.0" karma: "npm:^6.4.2" - lodash: "npm:^4.17.21" mocha: "npm:^10.2.0" npm-run-all: "npm:^4.1.5" react: "npm:^16.14.0"