Skip to content

Commit d201a23

Browse files
authored
Merge pull request #8151 from ryuwd/roneil-fix-graph-datetime-offset
fix: prevent any local-UTC offset being introduced in plots
2 parents 5299b4a + de475ba commit d201a23

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/DIRAC/Core/Utilities/Graphs/GraphUtilities.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ def convert_to_datetime(dstring):
7373
# Use utcfromtimestamp for UTC time
7474
results = datetime.datetime.utcfromtimestamp(int(results))
7575
elif isinstance(results, datetime.datetime):
76-
results = results.astimezone(datetime.timezone.utc) # Ensure in UTC
76+
if results.tzinfo is not None:
77+
# non-naive datetime: convert to UTC
78+
results = results.astimezone(datetime.timezone.utc)
79+
else:
80+
# DIRAC naive datetimes are UTC everywhere: add tzinfo
81+
results = results.replace(tzinfo=datetime.timezone.utc)
7782
else:
7883
raise ValueError("Unknown datetime type!")
7984
except Exception:

0 commit comments

Comments
 (0)