diff options
author | Brock Mendel <jbrockmendel@gmail.com> | 2017-12-13 09:08:28 -0800 |
---|---|---|
committer | Paul Ganssle <paul@ganssle.io> | 2018-03-11 18:15:59 -0400 |
commit | 87961706661f4fb95a5057ebb0ccf8ebad3f5efc (patch) | |
tree | a8a519a5396ca7a61c600d8a5a70b40541042fe3 /dateutil/parser | |
parent | 1dfa77a2e87dcfd1cf277c69c27dea0ec8530f77 (diff) | |
download | dateutil-87961706661f4fb95a5057ebb0ccf8ebad3f5efc.tar.gz |
warn instead of raising... for now
edit warning per suggestion
Diffstat (limited to 'dateutil/parser')
-rw-r--r-- | dateutil/parser/_parser.py | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/dateutil/parser/_parser.py b/dateutil/parser/_parser.py index a5ec2fb..de81fdc 100644 --- a/dateutil/parser/_parser.py +++ b/dateutil/parser/_parser.py @@ -34,6 +34,7 @@ import datetime import re import string import time +import warnings from calendar import monthrange from io import StringIO @@ -613,14 +614,6 @@ class parser(object): if not ignoretz: ret = self._build_tzaware(ret, res, tzinfos) - elif not res.tzname and not res.tzoffset: - # i.e. no timezone information was found. - pass - else: - # tz-like string was parsed but we don't know what to do - # with it - raise ValueError(res.tzname) - if kwargs.get('fuzzy_with_tokens', False): return ret, skipped_tokens else: @@ -1153,9 +1146,18 @@ class parser(object): elif res.tzoffset: aware = naive.replace(tzinfo=tz.tzoffset(res.tzname, res.tzoffset)) - else: - # TODO: this is really only the right thing to do if no tz - # information was found. + elif not res.tzname and not res.tzoffset: + # i.e. no timezone information was found. + aware = naive + + elif res.tzname: + # tz-like string was parsed but we don't know what to do + # with it + warnings.warn("tzname {tzname} identified but not understood. " + "Pass `tzinfos` argument in order to correctly " + "return a timezone-aware datetime. In a future " + "version, this raise an " + "exception.".format(tzname=res.tzname)) aware = naive return aware |