Skip to content

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.

fix: render dates in table using local tz (#2872)

Myles Scolnicka0086a55a34f
diff --git a/frontend/src/components/data-table/columns.tsx b/frontend/src/components/data-table/columns.tsx
index abcd3b59cc..4edaec6928 100644
--- a/frontend/src/components/data-table/columns.tsx
+++ b/frontend/src/components/data-table/columns.tsx
@@ -2,6 +2,7 @@
"use no memo";
import type { ColumnDef } from "@tanstack/react-table";
+import { format as formatDate } from "date-fns";
import {
DataTableColumnHeader,
DataTableColumnHeaderWithSummary,
@@ -15,6 +16,7 @@ import type { FieldTypesWithExternalType } from "./types";
import { UrlDetector } from "./url-detector";
import { cn } from "@/utils/cn";
import { uniformSample } from "./uniformSample";
+import { DatePopover } from "./date-popover";
function inferDataType(value: unknown): DataType {
if (typeof value === "string") {
@@ -184,6 +186,20 @@ export function generateColumns<T>({
</div>
);
}
+
+ if (value instanceof Date) {
+ // e.g. 2010-10-07 17:15:00
+ const type =
+ column.columnDef.meta?.dataType === "date" ? "date" : "datetime";
+ return (
+ <div className={getCellStyleClass(justify, wrapped)}>
+ <DatePopover date={value} type={type}>
+ {formatDate(value, "yyyy-MM-dd HH:mm:ss")}
+ </DatePopover>
+ </div>
+ );
+ }
+
return (
<div className={getCellStyleClass(justify, wrapped)}>
<MimeCell value={value} />
diff --git a/frontend/src/plugins/impl/vega/__tests__/vega.test.ts b/frontend/src/plugins/impl/vega/__tests__/vega.test.ts
index bdd0487c86..80eed64ee5 100644
--- a/frontend/src/plugins/impl/vega/__tests__/vega.test.ts
+++ b/frontend/src/plugins/impl/vega/__tests__/vega.test.ts
@@ -26,12 +26,12 @@ active,username,id
expect(data).toMatchInlineSnapshot(`
[
{
- "active": "2023-08-14T19:28:47.000Z",
+ "active": 2023-08-14T19:28:47.000Z,
"id": 1994308,
"username": "akshayka",
},
{
- "active": "2023-08-14T21:30:17.000Z",
+ "active": 2023-08-14T21:30:17.000Z,
"id": 5108954,
"username": "mscolnick",
},
@@ -385,7 +385,7 @@ Bob.Jones,25
expect(data).toMatchInlineSnapshot(`
[
{
- "created_at": "2024-01-01T00:00:00.000Z",
+ "created_at": 2024-01-01T00:00:00.000Z,
"name": "Alice",
},
{
diff --git a/frontend/src/plugins/impl/vega/loader.ts b/frontend/src/plugins/impl/vega/loader.ts
index afa438b8ad..c21d69689a 100644
--- a/frontend/src/plugins/impl/vega/loader.ts
+++ b/frontend/src/plugins/impl/vega/loader.ts
@@ -71,7 +71,7 @@ const DATE_MIDDLEWARE: Middleware = () => {
return null;
}
try {
- return new Date(value).toISOString();
+ return new Date(value);
} catch {
Logger.warn(`Failed to parse date: ${value}`);
return value;
diff --git a/marimo/_smoke_tests/issues/2817_timezones.py b/marimo/_smoke_tests/issues/2817_timezones.py
new file mode 100644
index 0000000000..140a6a263b
--- /dev/null
+++ b/marimo/_smoke_tests/issues/2817_timezones.py
@@ -0,0 +1,43 @@
+import marimo
+
+__generated_with = "0.9.19"
+app = marimo.App(width="medium")
+
+
+def __():
+ import polars as pl
+ from datetime import datetime, date
+
+ d = datetime(2010, 10, 7, 13, 15)
+
+ pl.DataFrame({"timestamp": [d], "date": [d.date()]})
+ return d, date, datetime, pl
+
+
+def __(d):
+ [d, d.date()]
+ return
+
+
+def __(date, pl):
+ import altair as alt
+
+ data = pl.DataFrame(
+ {
+ "Date": [
+ date(2021, 1, 1),
+ date(2021, 1, 2),
+ date(2021, 1, 3),
+ ],
+ "Value": [23, 45, 67],
+ }
+ )
+ alt.Chart(data).mark_line().encode(x="Date:T", y="Value:Q").interactive()
+ return alt, data
+
+
+if __name__ == "__main__":
+ app.run()