[geany/infrastructure] 3e8e0a: Use dateutil.parser instead of manually trying to parse a Github date
Enrico Tröger
git-noreply at geany.org
Thu Nov 1 13:42:17 UTC 2012
Branch: refs/heads/master
Author: Enrico Tröger <enrico.troeger at uvena.de>
Committer: Enrico Tröger <enrico.troeger at uvena.de>
Date: Thu, 01 Nov 2012 13:42:17 UTC
Commit: 3e8e0aa4030b4df0413eb0fc47b86d4616f8dfed
https://github.com/geany/infrastructure/commit/3e8e0aa4030b4df0413eb0fc47b86d4616f8dfed
Log Message:
-----------
Use dateutil.parser instead of manually trying to parse a Github date
Unfortunately this adds a requirement on the dateutil package but
this way parsing Github dates is way easier and probably safer.
Modified Paths:
--------------
scripts/git_hooks/github_commit_mail.py
Modified: scripts/git_hooks/github_commit_mail.py
23 files changed, 3 insertions(+), 20 deletions(-)
===================================================================
@@ -9,7 +9,7 @@
'''
-from datetime import datetime, timedelta
+from dateutil import parser as dateutil_parser
from email.mime.text import MIMEText
from email.Header import Header
from email.utils import formatdate, formataddr
@@ -137,7 +137,7 @@ def _adapt_commit_info(self, full_commit_info):
committer_name = full_commit_info['commit']['committer']['name']
commit_datetime = self._parse_commit_date(full_commit_info['commit']['committer']['date'])
commit_date = mktime(commit_datetime.timetuple())
- commit_date_formatted = commit_datetime.strftime('%a, %d %b %Y %H:%M:%S')
+ commit_date_formatted = commit_datetime.strftime('%a, %d %b %Y %H:%M:%S %Z')
commit_message = full_commit_info['commit']['message']
short_commit_message = self._get_short_commit_message(commit_message)
short_hash = commit[:6]
@@ -175,24 +175,7 @@ def _get_name(self, full_commit_info, name):
#----------------------------------------------------------------------
def _parse_commit_date(self, date_raw):
- # unfortunately, Python's strptime cannot parse numeric timezone offsets (anymore since 2.6)
- # so we need to do it on our own, example date: 2012-01-08T04:44:21-08:00
- date_to_parse = date_raw[:-6]
- timezone_offset = date_raw[-6:]
- # parse date
- date = datetime.strptime(date_to_parse, '%Y-%m-%dT%H:%M:%S')
- # handle timezone information
- timezone_offset = timezone_offset.replace(':', '')
- try:
- offset = int(timezone_offset)
- except ValueError:
- self._logger.warn(
- u'Error on parsing timezone information "%s" (%s)' % (timezone_offset, date_raw))
- offset = 0
-
- delta = timedelta(hours=offset / 100.0)
- date -= delta
- return date
+ return dateutil_parser.parse(date_raw)
#----------------------------------------------------------------------
def _get_short_commit_message(self, short_commit_message):
--------------
This E-Mail was brought to you by github_commit_mail.py (Source: TBD).
More information about the Commits
mailing list