diff options
author | Vincent Driessen <me@nvie.com> | 2016-04-19 14:27:25 +0200 |
---|---|---|
committer | Vincent Driessen <me@nvie.com> | 2016-04-19 21:52:06 +0200 |
commit | a2c8c7f86e6a61307311ea6036dac4f89b64b500 (patch) | |
tree | 2c01a7478e1d66b6d632bdbc83030a3779661657 /git/test/test_commit.py | |
parent | 504870e633eeb5fc1bd7c33b8dde0eb62a5b2d12 (diff) | |
download | gitpython-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/test/test_commit.py')
-rw-r--r-- | git/test/test_commit.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/git/test/test_commit.py b/git/test/test_commit.py index 3e958edf..23b7154a 100644 --- a/git/test/test_commit.py +++ b/git/test/test_commit.py @@ -32,6 +32,8 @@ import time import sys import re import os +from datetime import datetime +from git.objects.util import tzoffset, utc def assert_commit_serialization(rwrepo, commit_id, print_performance_info=False): @@ -343,3 +345,12 @@ JzJMZDRLQLFvnzqZuCjE cstream = BytesIO() cmt._serialize(cstream) assert not re.search(r"^gpgsig ", cstream.getvalue().decode('ascii'), re.MULTILINE) + + def test_datetimes(self): + commit = self.rorepo.commit('4251bd5') + assert commit.authored_date == 1255018625 + assert commit.committed_date == 1255026171 + assert commit.authored_datetime == datetime(2009, 10, 8, 18, 17, 5, tzinfo=tzoffset(-7200)), commit.authored_datetime # noqa + assert commit.authored_datetime == datetime(2009, 10, 8, 16, 17, 5, tzinfo=utc), commit.authored_datetime + assert commit.committed_datetime == datetime(2009, 10, 8, 20, 22, 51, tzinfo=tzoffset(-7200)) + assert commit.committed_datetime == datetime(2009, 10, 8, 18, 22, 51, tzinfo=utc), commit.committed_datetime |