-
Notifications
You must be signed in to change notification settings - Fork 417
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
chore: swap out deprecated datetime's utcnow and utcfromtimestamp #11850
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good for profiling. Timestamps are consistent with what we had before. Thanks!
Datadog ReportBranch report: ✅ 0 Failed, 87 Passed, 1468 Skipped, 4m 1.45s Total duration (35m 33.76s time saved) |
See #11608 and #11497.
Starting with Python 3.12, there were changes to datetime:
The result is that the usage of utcnow and utcfromtimestamp now throw deprecation warnings when used, ie:
There's a difference of
+00:00
between the old version and the new format.For utcnow -> now
datetime.datetime.utcnow().isoformat()
|'2025-01-02T19:51:32.579733'
datetime.datetime.now(datetime.timezone.utc).isoformat()
|'2025-01-02T19:51:02.275232+00:00'
For utcfromtimestamp -> fromtimestamp
Assume that
end_time_ns=1735848645000000000
:(datetime.datetime.fromtimestamp(end_time_ns / 1e9, tz=datetime.timezone.utc).replace(microsecond=0).isoformat() + "Z")
'2025-01-02T20:10:45+00:00Z'
(datetime.datetime.utcfromtimestamp(end_time_ns / 1e9).replace(microsecond=0).isoformat() + "Z")
'2025-01-02T20:10:45Z'
As a result, I attempted remove the trailing ones to be consistent with the old format, but can bring it back.
Checklist
Reviewer Checklist