summaryrefslogtreecommitdiff
path: root/git/objects/commit.py
diff options
context:
space:
mode:
authorVincent Driessen <me@nvie.com>2016-04-19 14:27:25 +0200
committerVincent Driessen <me@nvie.com>2016-04-19 21:52:06 +0200
commita2c8c7f86e6a61307311ea6036dac4f89b64b500 (patch)
tree2c01a7478e1d66b6d632bdbc83030a3779661657 /git/objects/commit.py
parent504870e633eeb5fc1bd7c33b8dde0eb62a5b2d12 (diff)
downloadgitpython-a2c8c7f86e6a61307311ea6036dac4f89b64b500.tar.gz
Add support for getting "aware" datetime info
This adds 2 properties to commits. Their values are derived from the existing data stored on them, but this makes them more conveniently queryable: - authored_datetime - committed_datetime These return "aware" datetimes, so they are effectively companions to their raw timestamp equivalents, respectively `authored_date` and `committed_date`. These datetime instances are convenient structures since they show the author-local commit date and their UTC offset.
Diffstat (limited to 'git/objects/commit.py')
-rw-r--r--git/objects/commit.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/git/objects/commit.py b/git/objects/commit.py
index d067b718..dc722f97 100644
--- a/git/objects/commit.py
+++ b/git/objects/commit.py
@@ -21,7 +21,8 @@ from .util import (
Serializable,
parse_date,
altz_to_utctz_str,
- parse_actor_and_date
+ parse_actor_and_date,
+ from_timestamp,
)
from git.compat import text_type
@@ -145,6 +146,14 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
# END handle attrs
@property
+ def authored_datetime(self):
+ return from_timestamp(self.authored_date, self.author_tz_offset)
+
+ @property
+ def committed_datetime(self):
+ return from_timestamp(self.committed_date, self.committer_tz_offset)
+
+ @property
def summary(self):
""":return: First line of the commit message"""
return self.message.split('\n', 1)[0]