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

Class _ymd

src/dateutil/parser/_parser.py:388–559  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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