Skip to content

Commit fec61fa

Browse files
committed
Fixed date coercion in .to_json() for export purposes.
1 parent 75171c2 commit fec61fa

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

highcharts_core/metaclasses.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,12 @@ def trim_dict(untrimmed: dict,
348348
as_dict[key] = trimmed_value
349349
# Date or Time
350350
elif checkers.is_date(value) or checkers.is_time(value):
351-
if to_json:
351+
if to_json and checkers.is_date(value):
352+
trimmed_value = validators.datetime(value)
353+
if not trimmed_value.tzinfo:
354+
trimmed_value = trimmed_value.replace(tzinfo=datetime.timezone.utc)
355+
as_dict[key] = trimmed_value.timestamp() * 1000
356+
elif to_json:
352357
as_dict[key] = value.isoformat()
353358
else:
354359
as_dict[key] = value

0 commit comments

Comments
 (0)