Skip to content

Commit 5425cf4

Browse files
tpellissierclaude
andcommitted
Preserve microseconds in datetime filter formatting
Include fractional seconds (.%f) when datetime.microsecond is non-zero to avoid silently truncating high-precision timestamps. Added test. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c354931 commit 5425cf4

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/PowerPlatform/Dataverse/models/filters.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ def _format_value(value: Any) -> str:
9191
# Convert timezone-aware datetimes to UTC; assume naive datetimes are UTC
9292
if value.tzinfo is not None:
9393
value = value.astimezone(timezone.utc)
94+
if value.microsecond:
95+
return value.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
9496
return value.strftime("%Y-%m-%dT%H:%M:%SZ")
9597
if isinstance(value, date):
9698
return value.strftime("%Y-%m-%d")

tests/unit/models/test_filters.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ def test_datetime_utc(self):
9898
dt = datetime(2024, 1, 15, 10, 30, 0, tzinfo=timezone.utc)
9999
self.assertEqual(_format_value(dt), "2024-01-15T10:30:00Z")
100100

101+
def test_datetime_with_microseconds(self):
102+
"""Microseconds should be preserved when non-zero."""
103+
dt = datetime(2024, 1, 15, 10, 30, 0, 123456)
104+
self.assertEqual(_format_value(dt), "2024-01-15T10:30:00.123456Z")
105+
101106
def test_datetime_non_utc_converted(self):
102107
"""Timezone-aware non-UTC datetimes should be converted to UTC."""
103108
eastern = timezone(timedelta(hours=-5))

0 commit comments

Comments
 (0)