Skip to content
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

Improve handling of str values for Duration #1165

Merged
merged 1 commit into from
Aug 15, 2021
Merged

Improve handling of str values for Duration #1165

merged 1 commit into from
Aug 15, 2021

Conversation

backbord
Copy link
Contributor

@backbord backbord commented Nov 13, 2020

Hi @mvantellingen,

I really like your project but recently stumbled into #876 when I wanted to specify a duration as "PT15M" and got "P%P" in the generated SOAP message.

Here's my attempt to improve the behaviour. Two simple and small test cases are included.
I hope you might consider merging the PR or giving advice if there's another desired way to do things.

In this PR, two things happen:

  • Passing in a datetime.timedelta value is allowed.
  • Passing in a str value will result in the str being parsed by isodate.parse_duration() to ensure the provided value is indeed an iso duration.
    The result of the parsing is then handed over to isodate.duration_isoformat() to produce the desired duration string.
    This round-trip mimics one of your test cases and results in builtins.Duration().xmlvalue("P0Y1347M0D") == "P1347M" where the superfluous zeros are eliminated. This should also ensure that the string is a valid duration in isoformat and raise a ValueError if it cannot be parsed as such.

Thanks and best regards,
Tim

Passing a str to `Duration.xmlvalue(value)` will result
in a properly formatted iso duration.
@mvantellingen mvantellingen merged commit 221d923 into mvantellingen:master Aug 15, 2021
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

Successfully merging this pull request may close these issues.

None yet

2 participants