Skip to content

Commit 234b74f

Browse files
Merge pull request #1039 from ap--/fix-timezone-error
Fix timezone error
2 parents d75201a + 3e613cd commit 234b74f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Diff for: src/setuptools_scm/git.py

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import re
77
import shlex
8+
import sys
89
import warnings
910

1011
from datetime import date
@@ -119,6 +120,8 @@ def parse_timestamp(timestamp_text: str) -> date | None:
119120
if "%c" in timestamp_text:
120121
log.warning("git too old -> timestamp is %r", timestamp_text)
121122
return None
123+
if sys.version_info < (3, 11) and timestamp_text.endswith("Z"):
124+
timestamp_text = timestamp_text[:-1] + "+00:00"
122125
return datetime.fromisoformat(timestamp_text).date()
123126

124127
res = run_git(

Diff for: testing/test_git.py

+16
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,22 @@ def test_git_getdate_badgit(
498498
assert git_wd.get_head_date() is None
499499

500500

501+
def test_git_getdate_git_2_45_0_plus(
502+
wd: WorkDir, caplog: pytest.LogCaptureFixture, monkeypatch: pytest.MonkeyPatch
503+
) -> None:
504+
wd.commit_testfile()
505+
git_wd = git.GitWorkdir(wd.cwd)
506+
fake_date_result = CompletedProcess(
507+
args=[], stdout="2024-04-30T22:33:10Z", stderr="", returncode=0
508+
)
509+
with patch.object(
510+
git,
511+
"run_git",
512+
Mock(return_value=fake_date_result),
513+
):
514+
assert git_wd.get_head_date() == date(2024, 4, 30)
515+
516+
501517
@pytest.fixture()
502518
def signed_commit_wd(monkeypatch: pytest.MonkeyPatch, wd: WorkDir) -> WorkDir:
503519
if not has_command("gpg", args=["--version"], warn=False):

0 commit comments

Comments
 (0)