Skip to content

Commit

Permalink
Always add timezone information to parsed datetimes; allow one to spe…
Browse files Browse the repository at this point in the history
…cify a default timezone.
  • Loading branch information
coddingtonbear committed Apr 14, 2014
1 parent f3166d3 commit ba28993
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
16 changes: 14 additions & 2 deletions bugwarrior/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from dateutil.parser import parse as parse_date
from jinja2 import Template
import pytz
import six
from twiggy import log

Expand Down Expand Up @@ -254,9 +255,20 @@ def get_processed_url(self, url):
return URLShortener().shorten(url)
return url

def parse_date(self, date):
def parse_date(self, date, timezone='UTC'):
""" Parse a date string into a datetime object.
:param `date`: A time string parseable by `dateutil.parser.parse`
:param `timezone`: The string timezone name (from `pytz.all_timezones`)
to use as a default should the parsed time string not include
timezone information.
"""
if date:
return parse_date(date)
date = parse_date(date)
if not date.tzinfo:
date = date.replace(tzinfo=pytz.timezone(timezone))
return date
return None

def build_default_description(
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#"jira-python",
#"taskw >= 0.8",
"dateutils >= 0.6.6",
"pytz",
"keyring",
"six",
"jinja2>=2.7.2",
Expand Down

0 comments on commit ba28993

Please sign in to comment.