diff --git a/gto/tag.py b/gto/tag.py index 43c9ec26..c3c92ecd 100644 --- a/gto/tag.py +++ b/gto/tag.py @@ -1,6 +1,6 @@ +import datetime import os import re -from datetime import datetime from enum import Enum from typing import FrozenSet, Iterable, Optional, Union @@ -124,7 +124,7 @@ class Tag(BaseModel): name: str version: Optional[str] stage: Optional[str] - created_at: datetime + created_at: datetime.datetime tag: GitTag class Config: @@ -132,9 +132,10 @@ class Config: def parse_tag(tag: GitTag): + tz = datetime.timezone(datetime.timedelta(minutes=int(tag.tag_time_offset))) return Tag( tag=tag, - created_at=datetime.fromtimestamp(tag.tag_time), + created_at=datetime.datetime.fromtimestamp(tag.tag_time, tz=tz), **parse_name(tag.name), ) diff --git a/tests/test_tag.py b/tests/test_tag.py index 1db10140..e0ee9efc 100644 --- a/tests/test_tag.py +++ b/tests/test_tag.py @@ -3,7 +3,7 @@ from gto.constants import Action from gto.exceptions import RefNotFound, TagExists -from gto.tag import create_tag, find, name_tag, parse_name +from gto.tag import create_tag, find, name_tag, parse_name, parse_tag def test_name_tag(scm: Git): @@ -148,3 +148,11 @@ def test_create_tag_repeated_tagname(scm: Git): def test_lightweight_tag(scm: Git): scm.tag("lightweight-tag@v0.0.1") assert find(scm=scm) == [] + + +@pytest.mark.usefixtures("repo_with_commit") +def test_parse_tag_created_at_timezone(scm: Git): + create_tag(scm, "nn#prod", rev="HEAD", message="msg") + tag = parse_tag(scm.get_tag("nn#prod")) + d = tag.created_at + assert d.tzinfo is not None and d.tzinfo.utcoffset(d) is not None