Skip to content

isoduration ignores trailing garbage when parsing. #21

@tomprince

Description

@tomprince

I was experimenting with the alternative duration format, and discovered some weird behavior:

>>> # Silently ignores alternate format when time is not provided
>>> isoduration.parse_duration('P0000-01-00')
Duration(DateDuration(years=Decimal('0'), months=Decimal('0'), days=Decimal('0'), weeks=Decimal('0')), TimeDuration(hours=Decimal('0'), minutes=Decimal('0'), seconds=Decimal('0')))
>>> # Doesn't handle alternate format duration with any of year/month/day being zero
>>> isoduration.parse_duration('P0000-00-00T00:00')
isoduration.parser.exceptions.UnparseableValue: Value could not be parsed as datetime: 0000-00-00T00:00
>>> # Ignores trailing numbers
>>> isoduration.parse_duration('P1MT1')
Duration(DateDuration(years=Decimal('0'), months=Decimal('1'), days=Decimal('0'), weeks=Decimal('0')), TimeDuration(hours=Decimal('0'), minutes=Decimal('0'), seconds=Decimal('0')))
>>> # Alternative format duration parsing accepts to many formats (e.g. YYYY-DDD)
>>> isoduration.parse_duration("P2020-123T00:00")
Duration(DateDuration(years=2020, months=5, days=2, weeks=Decimal('0')), TimeDuration(hours=0, minutes=0, seconds=0))
>>> # (note that this format causes the length in years to affect the number of days)
>>> isoduration.parse_duration("P2021-123T00:00")
Duration(DateDuration(years=2020, months=5, days=2, weeks=Decimal('0')), TimeDuration(hours=0, minutes=0, seconds=0))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions