summaryrefslogtreecommitdiff
path: root/dateutil/parser/_parser.py
diff options
context:
space:
mode:
authorPaul Ganssle <paul@ganssle.io>2017-11-09 15:36:08 -0500
committerPaul Ganssle <paul@ganssle.io>2017-11-09 17:44:55 -0500
commitbfa44c7717367dcf5af17947d4894c239ff95638 (patch)
tree9552526b7cd9d6bb1d237167b5eb5685061b9aad /dateutil/parser/_parser.py
parent64c6c85ded28dea8a617b91258aabf269d1ca34a (diff)
downloaddateutil-git-bfa44c7717367dcf5af17947d4894c239ff95638.tar.gz
Use the self.ystridx already found for unambiguous year > 99 dates
Diffstat (limited to 'dateutil/parser/_parser.py')
-rw-r--r--dateutil/parser/_parser.py36
1 files changed, 6 insertions, 30 deletions
diff --git a/dateutil/parser/_parser.py b/dateutil/parser/_parser.py
index 9ac0751..91a4182 100644
--- a/dateutil/parser/_parser.py
+++ b/dateutil/parser/_parser.py
@@ -38,6 +38,7 @@ import time
from calendar import monthrange
from io import StringIO
+import six
from six import binary_type, integer_types, text_type
from .. import relativedelta
@@ -378,10 +379,9 @@ class parserinfo(object):
class _ymd(list):
- def __init__(self, tzstr, *args, **kwargs):
+ def __init__(self, *args, **kwargs):
super(self.__class__, self).__init__(*args, **kwargs)
self.century_specified = False
- self.tzstr = tzstr
self.dstridx = None
self.mstridx = None
self.ystridx = None
@@ -412,30 +412,6 @@ class _ymd(list):
year = self[self.ystridx]
return 1 <= value <= monthrange(year, month)[1]
- @staticmethod
- def token_could_be_year(token, year):
- try:
- return int(token) == year
- except ValueError:
- return False
-
- @staticmethod
- def find_potential_year_tokens(year, tokens):
- return [token for token in tokens
- if _ymd.token_could_be_year(token, year)]
-
- def find_probable_year_index(self, tokens):
- """
- attempt to deduce if a pre 100 year was lost
- due to padded zeros being taken off
- """
- for index, token in enumerate(self):
- potential_year_tokens = _ymd.find_potential_year_tokens(token,
- tokens)
- if (len(potential_year_tokens) == 1 and
- len(potential_year_tokens[0]) > 2):
- return index
-
def append(self, val, label=None):
if hasattr(val, '__len__'):
if val.isdigit() and len(val) > 2:
@@ -526,7 +502,7 @@ class _ymd(list):
else:
if (self[0] > 31 or
- self.find_probable_year_index(_timelex.split(self.tzstr)) == 0 or
+ self.ystridx == 0 or
(yearfirst and self[1] <= 12 and self[2] <= 31)):
# 99-01-01
if dayfirst and self[2] <= 12:
@@ -725,7 +701,7 @@ class parser(object):
skipped_idxs = []
# year/month/day list
- ymd = _ymd(timestr)
+ ymd = _ymd()
len_l = len(l)
i = 0
@@ -963,7 +939,7 @@ class parser(object):
if value is not None:
ymd.append(value, 'M')
else:
- raise InvalidDatetimeError(ymd.tzstr)
+ raise InvalidDatetimeError()
if idx + 3 < len_l and tokens[idx + 3] == sep:
# We have three members
@@ -999,7 +975,7 @@ class parser(object):
ymd.append(value)
elif not fuzzy:
- raise InvalidDatetimeError(ymd.tzstr)
+ raise InvalidDatetimeError()
return idx