From 6b923f3129a91e5ed207112346e03e796f1cf3f5 Mon Sep 17 00:00:00 2001 From: ParseThis Date: Sat, 14 Apr 2018 14:57:26 -0400 Subject: Allow user to specify None as tzinfo value This commit allows the user to specify None when the dont care about the time zone information in the date time parse. --- dateutil/parser/_parser.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'dateutil/parser/_parser.py') diff --git a/dateutil/parser/_parser.py b/dateutil/parser/_parser.py index 79cd2bb..f749bdf 100644 --- a/dateutil/parser/_parser.py +++ b/dateutil/parser/_parser.py @@ -1125,16 +1125,14 @@ class parser(object): tzdata = tzinfos(tzname, tzoffset) else: tzdata = tzinfos.get(tzname) - - if isinstance(tzdata, datetime.tzinfo): + # handle case where tzinfo is paased an options that returns None + # eg tzinfos = {'BRST' : None} + if isinstance(tzdata, datetime.tzinfo) or tzdata is None: tzinfo = tzdata elif isinstance(tzdata, text_type): tzinfo = tz.tzstr(tzdata) elif isinstance(tzdata, integer_types): tzinfo = tz.tzoffset(tzname, tzdata) - else: - raise ValueError("Offset must be tzinfo subclass, " - "tz string, or int offset.") return tzinfo def _build_tzaware(self, naive, res, tzinfos): @@ -1170,7 +1168,7 @@ class parser(object): 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 " + "version, this will raise an " "exception.".format(tzname=res.tzname), category=UnknownTimezoneWarning) aware = naive -- cgit v1.2.1