diff --git a/docs/recipes/git-show.rst b/docs/recipes/git-show.rst index 249a6aa..0f4935d 100644 --- a/docs/recipes/git-show.rst +++ b/docs/recipes/git-show.rst @@ -31,7 +31,7 @@ Show SHA hash Show diff ====================================================================== - >>> diff = commit.parents[0].tree.diff_to_tree(commit.tree) + >>> diff = repo.diff(commit.parents[0], commit) ====================================================================== Show all files in commit @@ -41,14 +41,37 @@ Show all files in commit >>> print(e.name) ====================================================================== -Produce something like a `git show` message +Produce something like a ``git show`` message ====================================================================== +In order to display timezone information you have to create a subclass of +tzinfo as described in the `Python datetime documentation`_:: + + from datetime import tzinfo, timedelta + class FixedOffset(tzinfo): + """Fixed offset in minutes east from UTC.""" + + def __init__(self, offset): + self.__offset = timedelta(minutes = offset) + + def utcoffset(self, dt): + return self.__offset + + def tzname(self, dt): + return None + + def dst(self, dt): + return timedelta(0) # dealing with DST would be too complicated + +.. _Python datetime documentation: https://docs.python.org/2/library/datetime.html#tzinfo-objects + +Then you can make your message: + >>> from __future__ import unicode_literals >>> from datetime import datetime - >>> import pytz - >>> tzinfo = pytz.timezone('Europe/Berlin') - >>> dt = datetime.fromtimestamp(float(commit.commit_time), tzinfo) + >>> + >>> tzinfo = FixedOffset(commit.author.offset) + >>> dt = datetime.fromtimestamp(float(commit.author.time), tzinfo) >>> timestr = dt.strftime('%c %z') >>> msg = '\n'.join(['commit {}'.format(commit.tree_id.hex), ... 'Author: {} <{}>'.format(commit.author.name, commit.author.email),