Skip to content

Error parsing ISO8601 duration with negative sign #532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jacobg opened this issue Feb 1, 2021 · 1 comment
Open

Error parsing ISO8601 duration with negative sign #532

jacobg opened this issue Feb 1, 2021 · 1 comment

Comments

@jacobg
Copy link

jacobg commented Feb 1, 2021

For example, -PT8H is a valid IOS 8601 duration. But pendulum raises an error when trying to parse it.

>>> pendulum.parse('-PT8H')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/j/workspace/service-dev/p/env/lib/python3.7/site-packages/pendulum/parser.py", line 29, in parse
    return _parse(text, **options)
  File "/Users/j/workspace/service-dev/p/env/lib/python3.7/site-packages/pendulum/parser.py", line 45, in _parse
    parsed = base_parse(text, **options)
  File "/Users/j/workspace/service-dev/p/env/lib/python3.7/site-packages/pendulum/parsing/__init__.py", line 74, in parse
    return _normalize(_parse(text, **_options), **_options)
  File "/Users/j/workspace/service-dev/p/env/lib/python3.7/site-packages/pendulum/parsing/__init__.py", line 128, in _parse
    raise ParserError("Unable to parse string [{}]".format(text))
pendulum.parsing.exceptions.ParserError: Unable to parse string [-PT8H]
@Flix6x
Copy link

Flix6x commented Feb 22, 2021

This would be a nice addition. Technically, ISO 8601 section 2.1.6 defines duration as a "non-negative quantity" (so afaik it is not a "valid" ISO8601 duration) but other libraries have consolidated negative durations nonetheless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants