Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#YYYYWwwD
#YYYY-DDD
#YYYYDDD
if isodatestr.startswith('+') or isodatestr.startswith('-'):
raise NotImplementedError('ISO 8601 extended year representation not supported.')
isodatestrlen = len(isodatestr)
if isodatestr.find('W') != -1:
#Handle ISO 8601 week date format
hyphens_present = 1 if isodatestr.find('-') != -1 else 0
week_date_len = 7 + hyphens_present
weekday_date_len = 8 + 2*hyphens_present
if isodatestrlen == week_date_len:
#YYYY-Www
#YYYYWww
return DateResolution.Week
elif isodatestrlen == weekday_date_len:
#YYYY-Www-D
#YYYYWwwD
return DateResolution.Weekday
else:
raise ValueError('String is not a valid ISO 8601 week date.')
#If the size of the string of 4 or less, assume its a truncated year representation
if len(isodatestr) <= 4:
return DateResolution.Year
#An ISO string may be a calendar represntation if:
# 1) When split on a hyphen, the sizes of the parts are 4, 2, 2 or 4, 2
# 2) There are no hyphens, and the length is 8
datestrsplit = isodatestr.split('-')