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/test/test_commit.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'git/test/test_commit.py') 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 -- cgit v1.2.1