From f779409af39f47bedf3734bb31ee88b03cf5dc5e Mon Sep 17 00:00:00 2001
From: Frazer McLean <frazer@frazermclean.co.uk>
Date: Mon, 21 Oct 2024 23:40:07 +0200
Subject: [PATCH 1/4] Test on 3.13

---
 .github/workflows/main.yml | 6 +++---
 tox.ini                    | 3 ++-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index c0a89e5..f5dc283 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -27,7 +27,7 @@ jobs:
     strategy:
       fail-fast: false
       matrix:
-        python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
+        python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
 
     steps:
       - uses: "actions/checkout@v4"
@@ -54,7 +54,7 @@ jobs:
     strategy:
       fail-fast: false
       matrix:
-        python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
+        python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
         arch: ["x86", "x64"]
 
     env:
@@ -84,7 +84,7 @@ jobs:
     strategy:
       fail-fast: false
       matrix:
-        python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
+        python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
 
     steps:
       - uses: "actions/checkout@v4"
diff --git a/tox.ini b/tox.ini
index 499ed52..8d5108a 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,5 @@
 [tox]
-envlist = py{38,39,310,311,312}{,-nospeedups},pypy,docs
+envlist = py{38,39,310,311,312,313}{,-nospeedups},pypy,docs
 
 [testenv]
 extras =
@@ -32,3 +32,4 @@ python =
     3.10: py310
     3.11: py311, docs
     3.12: py312
+    3.13: py313

From 05f399b763a88076d2801b4ee956308db35752d2 Mon Sep 17 00:00:00 2001
From: Frazer McLean <frazer@frazermclean.co.uk>
Date: Mon, 21 Oct 2024 23:41:09 +0200
Subject: [PATCH 2/4] Stop using datetime.utcfromtimestamp

---
 src/logbook/compat.py  | 6 ++++--
 src/logbook/helpers.py | 8 ++++++++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/logbook/compat.py b/src/logbook/compat.py
index c79fef1..6f2cbea 100644
--- a/src/logbook/compat.py
+++ b/src/logbook/compat.py
@@ -12,10 +12,12 @@
 import sys
 import warnings
 from collections.abc import Mapping
-from datetime import date, datetime, timezone
+from datetime import timezone
 
 import logbook
 
+from .helpers import datetime_utcfromtimestamp
+
 
 def redirect_logging(set_root_logger_level=True):
     """Permanently redirects logging to the stdlib.  This also
@@ -140,7 +142,7 @@ def convert_time(self, timestamp):
         """Converts the UNIX timestamp of the old record into a
         datetime object as used by logbook.
         """
-        return datetime.utcfromtimestamp(timestamp)
+        return datetime_utcfromtimestamp(timestamp)
 
     def convert_record(self, old_record):
         """Converts an old logging record into a logbook log record."""
diff --git a/src/logbook/helpers.py b/src/logbook/helpers.py
index eb58304..b9e659b 100644
--- a/src/logbook/helpers.py
+++ b/src/logbook/helpers.py
@@ -153,8 +153,16 @@ def datetime_utcnow():
         """
         return datetime.now(timezone.utc).replace(tzinfo=None)
 
+    def datetime_utcfromtimestamp(timestamp):
+        """datetime.utcfromtimesetamp() but doesn't emit a deprecation warning.
+
+        Will be fixed by https://github.com/getlogbook/logbook/issues/353
+        """
+        return datetime.fromtimestamp(timestamp, timezone.utc).replace(tzinfo=None)
+
 else:
     datetime_utcnow = datetime.utcnow
+    datetime_utcfromtimestamp = datetime.utcfromtimestamp
 
 
 def format_iso8601(d=None):

From cbb63dd384bd8618faa7dc20a0946215153579f7 Mon Sep 17 00:00:00 2001
From: Frazer McLean <frazer@frazermclean.co.uk>
Date: Mon, 21 Oct 2024 23:48:32 +0200
Subject: [PATCH 3/4] Replace datetime.utcnow in tests

---
 tests/test_logging_times.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/test_logging_times.py b/tests/test_logging_times.py
index a27bf06..46da2c9 100644
--- a/tests/test_logging_times.py
+++ b/tests/test_logging_times.py
@@ -1,4 +1,4 @@
-from datetime import datetime, timedelta, tzinfo
+from datetime import datetime, timedelta, timezone, tzinfo
 
 import pytest
 
@@ -25,7 +25,7 @@ def test_timedate_format(activation_strategy, logger):
 
     # get the expected difference between local and utc time
     t1 = datetime.now()
-    t2 = datetime.utcnow()
+    t2 = datetime.now(timezone.utc).replace(tzinfo=None)
 
     tz_minutes_diff = (t1 - t2).total_seconds() / 60.0
 

From 44f5e7f774574e3891e40a2b96cf799ae50f82ad Mon Sep 17 00:00:00 2001
From: Frazer McLean <frazer@frazermclean.co.uk>
Date: Tue, 22 Oct 2024 00:02:55 +0200
Subject: [PATCH 4/4] Add 3.13 classifier

---
 pyproject.toml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/pyproject.toml b/pyproject.toml
index 49bb0ad..1f038c3 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -21,6 +21,7 @@ classifiers = [
     "Programming Language :: Python :: 3.10",
     "Programming Language :: Python :: 3.11",
     "Programming Language :: Python :: 3.12",
+    "Programming Language :: Python :: 3.13",
 ]
 requires-python = ">=3.8"
 dynamic = ["version"]