Skip to content

Commit 2aac918

Browse files
committed
fix: ensure using UTC
1 parent e75f7dd commit 2aac918

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

integration.png

43.2 KB
Loading

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,18 @@ def convert_to_datetime(dstring):
7070
else:
7171
results = eval(str(dstring), {"__builtins__": None, "time": time, "math": math}, {})
7272
if isinstance(results, (int, float)):
73+
# Use utcfromtimestamp for UTC time
7374
results = datetime.datetime.utcfromtimestamp(int(results))
7475
elif isinstance(results, datetime.datetime):
75-
pass
76+
results = results.astimezone(datetime.timezone.utc) # Ensure in UTC
7677
else:
7778
raise ValueError("Unknown datetime type!")
7879
except Exception:
7980
t = None
8081
for dateformat in datestrings:
8182
try:
8283
t = time.strptime(dstring, dateformat)
83-
timestamp = calendar.timegm(t) # -time.timezone
84+
timestamp = calendar.timegm(t) # Convert to UTC timestamp
8485
results = datetime.datetime.utcfromtimestamp(timestamp)
8586
break
8687
except Exception:
@@ -89,12 +90,12 @@ def convert_to_datetime(dstring):
8990
try:
9091
dstring = dstring.split(".", 1)[0]
9192
t = time.strptime(dstring, dateformat)
92-
timestamp = time.mktime(t) # -time.timezone
93+
timestamp = calendar.timegm(t) # Convert to UTC timestamp
9394
results = datetime.datetime.utcfromtimestamp(timestamp)
9495
except Exception:
9596
raise ValueError(
9697
"Unable to create time from string!\nExpecting "
97-
"format of: '12/06/06 12:54:67'\nRecieved:%s" % orig_string
98+
"format of: '12/06/06 12:54:67'\nReceived:%s" % orig_string
9899
)
99100
return results
100101

0 commit comments

Comments
 (0)