File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change 1+ import datetime
12import stat
23from abc import ABC , abstractmethod
34from dataclasses import dataclass
@@ -12,6 +13,11 @@ def S_ISGITLINK(m: int) -> bool:
1213 return stat .S_IFMT (m ) == S_IFGITLINK
1314
1415
16+ def _to_datetime (time : int , offset : int ) -> datetime .datetime :
17+ tz = datetime .timezone (datetime .timedelta (seconds = offset ))
18+ return datetime .datetime .fromtimestamp (time , tz = tz )
19+
20+
1521class GitObject (ABC ):
1622 @abstractmethod
1723 def open (self , mode : str = "r" , encoding : str = None ):
@@ -169,6 +175,14 @@ class GitCommit:
169175 author_time : int
170176 author_time_offset : int
171177
178+ @property
179+ def commit_datetime (self ) -> datetime .datetime :
180+ return _to_datetime (self .commit_time , self .commit_time_offset )
181+
182+ @property
183+ def author_datetime (self ) -> datetime .datetime :
184+ return _to_datetime (self .author_time , self .author_time_offset )
185+
172186
173187@dataclass
174188class GitTag :
@@ -180,3 +194,7 @@ class GitTag:
180194 tag_time : int
181195 tag_time_offset : int
182196 message : str
197+
198+ @property
199+ def tag_datetime (self ) -> datetime .datetime :
200+ return _to_datetime (self .tag_time , self .tag_time_offset )
You can’t perform that action at this time.
0 commit comments