MCPcopy Create free account
hub / github.com/dateutil/dateutil / _ymd

Class _ymd

src/dateutil/parser/_parser.py:394–565  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

392
393
394class _ymd(list):
395 def __init__(self, *args, **kwargs):
396 super(self.__class__, self).__init__(*args, **kwargs)
397 self.century_specified = False
398 self.dstridx = None
399 self.mstridx = None
400 self.ystridx = None
401
402 @property
403 def has_year(self):
404 return self.ystridx is not None
405
406 @property
407 def has_month(self):
408 return self.mstridx is not None
409
410 @property
411 def has_day(self):
412 return self.dstridx is not None
413
414 def could_be_day(self, value):
415 if self.has_day:
416 return False
417 elif not self.has_month:
418 return 1 <= value <= 31
419 elif not self.has_year:
420 # Be permissive, assume leap year
421 month = self[self.mstridx]
422 return 1 <= value <= monthrange(2000, month)[1]
423 else:
424 month = self[self.mstridx]
425 year = self[self.ystridx]
426 return 1 <= value <= monthrange(year, month)[1]
427
428 def append(self, val, label=None):
429 if hasattr(val, '__len__'):
430 if val.isdigit() and len(val) > 2:
431 self.century_specified = True
432 if label not in [None, 'Y']: # pragma: no cover
433 raise ValueError(label)
434 label = 'Y'
435 elif val > 100:
436 self.century_specified = True
437 if label not in [None, 'Y']: # pragma: no cover
438 raise ValueError(label)
439 label = 'Y'
440
441 super(self.__class__, self).append(int(val))
442
443 if label == 'M':
444 if self.has_month:
445 raise ValueError('Month is already set')
446 self.mstridx = len(self) - 1
447 elif label == 'D':
448 if self.has_day:
449 raise ValueError('Day is already set')
450 self.dstridx = len(self) - 1
451 elif label == 'Y':

Callers 2

test_YMD_could_be_dayFunction · 0.90
_parseMethod · 0.85

Calls

no outgoing calls

Tested by 1

test_YMD_could_be_dayFunction · 0.72