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: datetime UI element rendering in Docker containers (#6730)

Myles Scolnick025b45587dd0
diff --git a/frontend/src/plugins/impl/__tests__/DateTimePickerPlugin.test.tsx b/frontend/src/plugins/impl/__tests__/DateTimePickerPlugin.test.tsx
index 348b499705..31a1192fb5 100644
--- a/frontend/src/plugins/impl/__tests__/DateTimePickerPlugin.test.tsx
+++ b/frontend/src/plugins/impl/__tests__/DateTimePickerPlugin.test.tsx
@@ -42,4 +42,36 @@ describe("DateTimePickerPlugin", () => {
const datePicker = container.querySelector('[class*="group"]');
expect(datePicker).not.toBeNull();
});
+
+ it("should render with datetime.min and datetime.max edge cases", () => {
+ // Regression test for issue #6700
+ // Ensure the component can handle edge case dates like datetime.min
+ const plugin = new DateTimePickerPlugin();
+ const host = document.createElement("div");
+ const props: IPluginProps<string, DateTimeData> = {
+ host,
+ value: "2024-01-01T12:00:00",
+ setValue: (valueOrFn) => {
+ if (typeof valueOrFn === "function") {
+ valueOrFn("2024-01-01T12:00:00");
+ }
+ },
+ data: {
+ label: null,
+ // These are the exact values that datetime.min and datetime.max produce
+ start: "0001-01-01T00:00:00",
+ stop: "9999-12-31T23:59:59",
+ fullWidth: false,
+ },
+ functions: {},
+ };
+
+ // This should not throw an error
+ const { container } = render(plugin.render(props));
+
+ // Check if the component renders successfully
+ expect(container.innerHTML).not.toBe("");
+ const datePicker = container.querySelector('[class*="group"]');
+ expect(datePicker).not.toBeNull();
+ });
});
diff --git a/marimo/_plugins/ui/_impl/dates.py b/marimo/_plugins/ui/_impl/dates.py
index 2358535ea4..52436dfeee 100644
--- a/marimo/_plugins/ui/_impl/dates.py
+++ b/marimo/_plugins/ui/_impl/dates.py
@@ -263,8 +263,8 @@ class datetime(UIElement[Optional[str], Optional[dt.datetime]]):
initial_value=value.isoformat(timespec="seconds"),
label=label,
args={
- "start": self._start.strftime(self.DATETIME_FORMAT),
- "stop": self._stop.strftime(self.DATETIME_FORMAT),
+ "start": self._start.isoformat(timespec="seconds"),
+ "stop": self._stop.isoformat(timespec="seconds"),
"full-width": full_width,
"disabled": disabled,
},
diff --git a/tests/_plugins/ui/_impl/test_dates.py b/tests/_plugins/ui/_impl/test_dates.py
index 11c1d21b74..4bb8881512 100644
--- a/tests/_plugins/ui/_impl/test_dates.py
+++ b/tests/_plugins/ui/_impl/test_dates.py
@@ -2,6 +2,7 @@
from __future__ import annotations
import datetime
+from typing import cast
import pytest
@@ -60,6 +61,44 @@ def test_datetime() -> None:
assert dt.stop == datetime.datetime(2024, 12, 31, 23, 59)
+def test_datetime_min_max_iso_format() -> None:
+ """Test that datetime.min and datetime.max are formatted correctly with ISO 8601.
+
+ This test addresses issue #6700 where datetime.min was formatted as
+ "1-01-01T00:00:00" instead of "0001-01-01T00:00:00" in some Docker
+ environments, causing frontend parsing errors.
+ """
+ # Test with datetime.min
+ dt = ui.datetime()
+ start_arg: str = cast(str, dt._args.args.get("start"))
+ stop_arg: str = cast(str, dt._args.args.get("stop"))
+
+ # Verify that start and stop are properly formatted ISO 8601 strings
+ # with 4-digit years (not single digit years like "1-01-01")
+ assert start_arg is not None
+ assert stop_arg is not None
+ assert start_arg.startswith("0001-"), (
+ f"Expected start to begin with '0001-', got: {start_arg}"
+ )
+ assert stop_arg.startswith("9999-"), (
+ f"Expected stop to begin with '9999-', got: {stop_arg}"
+ )
+
+ # Verify exact format for datetime.min
+ assert start_arg == "0001-01-01T00:00:00"
+
+ # Test with explicit datetime.min and datetime.max
+ dt_explicit = ui.datetime(
+ start=datetime.datetime.min,
+ stop=datetime.datetime.max,
+ )
+ start_explicit = dt_explicit._args.args.get("start")
+ stop_explicit = dt_explicit._args.args.get("stop")
+
+ assert start_explicit == "0001-01-01T00:00:00"
+ assert stop_explicit == "9999-12-31T23:59:59"
+
+
def test_date_range() -> None:
# Test default initialization
dr = ui.date_range()