A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: date rendering resulting in 'Invalid Date' (#4697)
Myles Scolnick19e578fe8050
diff --git a/frontend/src/utils/__tests__/dates.test.ts b/frontend/src/utils/__tests__/dates.test.tsindex 3c9190a194..af2581950c 100644--- a/frontend/src/utils/__tests__/dates.test.ts+++ b/frontend/src/utils/__tests__/dates.test.ts@@ -39,6 +39,50 @@ describe("dates", () => {it("handles errors gracefully", () => {expect(prettyDate("invalid-date", "date")).toBe("Invalid Date");});++ it("handles numeric timestamp input", () => {+ const timestamp = 1_684_152_000_000; // 2023-05-15T12:00:00Z in milliseconds+ expect(prettyDate(timestamp, "date")).toMatch(/May 15, 2023/);+ });++ it("preserves timezone for datetime type", () => {+ // This date is in winter time to avoid daylight saving time issues+ const date = new Date("2023-01-15T15:30:00Z");+ expect(prettyDate(date.toISOString(), "datetime")).toMatch(+ /Jan 15, 2023/,+ );+ });++ it("drops timezone for date type by using UTC", () => {+ // Create a date that would be different days in different timezones+ const date = new Date("2023-05-15T23:30:00Z"); // Late in the day UTC+ expect(prettyDate(date.toISOString(), "date")).toMatch(/May 15, 2023/);+ });++ describe("with different locales", () => {+ // Save original implementation+ // eslint-disable-next-line @typescript-eslint/unbound-method+ const originalToLocaleDateString = Date.prototype.toLocaleDateString;++ afterAll(() => {+ // Restore original implementation+ Date.prototype.toLocaleDateString = originalToLocaleDateString;+ });++ it("formats date in fr-FR locale", () => {+ // Mock toLocaleDateString to simulate fr-FR locale+ // @ts-expect-error - we are mocking the method+ Date.prototype.toLocaleDateString = (locale, options) => {+ if (options?.timeZone === "UTC") {+ return "15 mai 2023";+ }+ return "15 mai 2023";+ };++ const date = new Date("2023-05-15T12:00:00Z");+ expect(prettyDate(date.toISOString(), "date")).toBe("15 mai 2023");+ });+ });});describe("exactDateTime", () => {diff --git a/frontend/src/utils/dates.ts b/frontend/src/utils/dates.tsindex 088136cce0..d99d2d6a65 100644--- a/frontend/src/utils/dates.ts+++ b/frontend/src/utils/dates.ts@@ -15,11 +15,15 @@ export function prettyDate(// If type is date, drop the timezone by rendering in UTC// since dates are absoluteif (type === "date") {- value = new Date(value).toLocaleDateString(undefined, {+ return new Date(value).toLocaleDateString(undefined, {+ year: "numeric",+ month: "short",+ day: "numeric",timeZone: "UTC",});}+ // For datetime, we keep the original timezonereturn new Date(value).toLocaleDateString(undefined, {year: "numeric",month: "short",