Skip to content

Commit 4bb360d

Browse files
committed
RavenDB-26793 Fix bulk-insert time-series timestamps to treat naive datetimes as UTC
Utils.get_unix_time_in_ms used datetime.timestamp(), which interprets a naive datetime in the machine's local timezone, so bulk-insert time-series timestamps were shifted by the local UTC offset on non-UTC machines (e.g. 2h on CET). The regular session path (Utils.datetime_to_string) treats naive datetimes as UTC; do the same here so both paths agree and results are timezone-independent.
1 parent 6514a75 commit 4bb360d

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

ravendb/tools/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from collections import Iterable, Sequence
1616

1717
from ravendb.tools.projection import create_entity_with_mapper
18-
from datetime import datetime, timedelta
18+
from datetime import datetime, timedelta, timezone
1919
from enum import Enum
2020
from threading import Timer
2121
from copy import deepcopy
@@ -958,4 +958,8 @@ def add_minutes(date: datetime, minutes: int):
958958

959959
@staticmethod
960960
def get_unix_time_in_ms(date: datetime) -> int:
961+
# Naive datetimes are treated as UTC (consistent with Utils.datetime_to_string) so that
962+
# bulk-insert time-series timestamps are not shifted by the machine's local UTC offset.
963+
if date.tzinfo is None:
964+
date = date.replace(tzinfo=timezone.utc)
961965
return int(date.timestamp() * 1000)

0 commit comments

Comments
 (0)