about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-05-16 07:19:42 +0200
committerGitHub <noreply@github.com>2025-05-16 07:19:42 +0200
commit9808b07bc5073f26b329f7fbf6b20e374ded1533 (patch)
treeb6ecae0e9daed0f07b4eb7d28e3b4f43f6641302
parente53b9f8fdd7be3357063cc82abe9a12f9014c13f (diff)
parent754b06f97869253968e0d6abf8105d047c327b62 (diff)
downloadrust-9808b07bc5073f26b329f7fbf6b20e374ded1533.tar.gz
rust-9808b07bc5073f26b329f7fbf6b20e374ded1533.zip
Rollup merge of #141009 - emmanuel-ferdman:master, r=marcoieni
Migrate to modern datetime API

# PR Summary
This small PR resolves the `datetime` library warnings:
```python
DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC). or datetime.datetime.utcnow()
```
Note that `.replace(tzinfo=None)` allows to keep the original behavior where the time appears as a naive UTC timestamp (i.e., without any timezone offset). Comparision:
```python
# With .utcnow() or .now(datetime.timezone.utc).replace(tzinfo=None)
Time,Idle
2025-05-14T15:40:25.013414,98.73417721518987

# With .now(datetime.timezone.utc)
Time,Idle
2025-05-14T15:40:25.013414+00:00,98.73417721518987
```
-rwxr-xr-xsrc/ci/cpu-usage-over-time.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/ci/cpu-usage-over-time.py b/src/ci/cpu-usage-over-time.py
index 3d9dc86734f..19a39f34953 100755
--- a/src/ci/cpu-usage-over-time.py
+++ b/src/ci/cpu-usage-over-time.py
@@ -170,7 +170,7 @@ print("Time,Idle")
 while True:
     time.sleep(1)
     next_state = State()
-    now = datetime.datetime.utcnow().isoformat()
+    now = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None).isoformat()
     idle = next_state.idle_since(cur_state)
     print("%s,%s" % (now, idle))
     sys.stdout.flush()