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

Method convertyear

src/dateutil/parser/_parser.py:354–372  ·  view source on GitHub ↗

Converts two-digit years to year within [-50, 49] range of self._year (current local time)

(self, year, century_specified=False)

Source from the content-addressed store, hash-verified

352 return self.TZOFFSET.get(name)
353
354 def convertyear(self, year, century_specified=False):
355 """
356 Converts two-digit years to year within [-50, 49]
357 range of self._year (current local time)
358 """
359
360 # Function contract is that the year is always positive
361 assert year >= 0
362
363 if year < 100 and not century_specified:
364 # assume current century to start
365 year += self._century
366
367 if year >= self._year + 50: # if too far in future
368 year -= 100
369 elif year < self._year - 50: # if too far in past
370 year += 100
371
372 return year
373
374 def validate(self, res):
375 # move to info

Callers 4

validateMethod · 0.95
_parseMethod · 0.80
test_convertyearFunction · 0.80

Calls

no outgoing calls

Tested by 2

test_convertyearFunction · 0.64