From a2c8c7f86e6a61307311ea6036dac4f89b64b500 Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Tue, 19 Apr 2016 14:27:25 +0200 Subject: 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. --- git/objects/commit.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'git/objects/commit.py') 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 @@ -144,6 +145,14 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): super(Commit, self)._set_cache_(attr) # 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""" -- cgit v1.2.1