Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.0] fix: ensure using UTC #7956

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/DIRAC/Core/Utilities/Graphs/GraphUtilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,18 @@ def convert_to_datetime(dstring):
else:
results = eval(str(dstring), {"__builtins__": None, "time": time, "math": math}, {})
if isinstance(results, (int, float)):
# Use utcfromtimestamp for UTC time
results = datetime.datetime.utcfromtimestamp(int(results))
elif isinstance(results, datetime.datetime):
pass
results = results.astimezone(datetime.timezone.utc) # Ensure in UTC
else:
raise ValueError("Unknown datetime type!")
except Exception:
t = None
for dateformat in datestrings:
try:
t = time.strptime(dstring, dateformat)
timestamp = calendar.timegm(t) # -time.timezone
timestamp = calendar.timegm(t) # Convert to UTC timestamp
results = datetime.datetime.utcfromtimestamp(timestamp)
break
except Exception:
Expand All @@ -89,12 +90,12 @@ def convert_to_datetime(dstring):
try:
dstring = dstring.split(".", 1)[0]
t = time.strptime(dstring, dateformat)
timestamp = time.mktime(t) # -time.timezone
timestamp = calendar.timegm(t) # Convert to UTC timestamp
results = datetime.datetime.utcfromtimestamp(timestamp)
except Exception:
raise ValueError(
"Unable to create time from string!\nExpecting "
"format of: '12/06/06 12:54:67'\nRecieved:%s" % orig_string
"format of: '12/06/06 12:54:67'\nReceived:%s" % orig_string
)
return results

Expand Down
Loading