Skip to content

Commit

Permalink
Digging into leap year bug and improvming tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Feb 29, 2016
1 parent bb46887 commit 34709c8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions panoramix/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import functools
import hashlib
import json
import logging

from dateutil.parser import parse
from sqlalchemy.types import TypeDecorator, TEXT
Expand Down Expand Up @@ -45,6 +46,7 @@ def parse_human_datetime(s):
generated strings
>>> from datetime import date, timedelta
>>> from dateutil.relativedelta import relativedelta
>>> parse_human_datetime('2015-04-03')
datetime.datetime(2015, 4, 3, 0, 0)
>>> parse_human_datetime('2/3/1969')
Expand All @@ -55,12 +57,18 @@ def parse_human_datetime(s):
True
>>> date.today() - timedelta(1) == parse_human_datetime('yesterday').date()
True
>>> parse_human_datetime('one year ago').date() == (datetime.now() - relativedelta(years=1) ).date()
True
"""
try:
dttm = parse(s)
except:
cal = parsedatetime.Calendar()
dttm = dttm_from_timtuple(cal.parse(s)[0])
try:
cal = parsedatetime.Calendar()
dttm = dttm_from_timtuple(cal.parse(s)[0])
except Exception as e:
logging.exception(e)
raise ValueError("Couldn't parse date string [{}]".format(s))
return dttm


Expand Down

0 comments on commit 34709c8

Please sign in to comment.