Skip to content

Commit

Permalink
fix(tags): parse timezone information from a tag
Browse files Browse the repository at this point in the history
  • Loading branch information
shcheklein committed Oct 9, 2023
1 parent 701fa68 commit 4880a5a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 4 additions & 3 deletions gto/tag.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -124,17 +124,18 @@ class Tag(BaseModel):
name: str
version: Optional[str]
stage: Optional[str]
created_at: datetime
created_at: datetime.datetime
tag: GitTag

class Config:
arbitrary_types_allowed = True


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),
)

Expand Down
10 changes: 9 additions & 1 deletion tests/test_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

0 comments on commit 4880a5a

Please sign in to comment.