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

Iso8601Duration produces incorrect results for negative values #5075

Closed
1 task done
ghost opened this issue May 17, 2022 · 1 comment · Fixed by #5076
Closed
1 task done

Iso8601Duration produces incorrect results for negative values #5075

ghost opened this issue May 17, 2022 · 1 comment · Fixed by #5076

Comments

@ghost
Copy link

ghost commented May 17, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Passing a negative duration TimeSpan from a StrawberryShake client to HotChocolate results in an incorrect deserialized value.

For example, passing the ISO8601 string "-P1D" results in a deserialized value of -1.00:00:02.1474836 and not -1:00:00:00.

Both StrawberryShake and HotChocolate share the almost identical Iso8601Duration code for serialization:

  • src/StrawberryShake/Client/src/Core/Serialization/Iso8601Duration.cs
  • src/HotChocolate/Core/src/Types/Types/Scalars/Iso8601Duration.cs

Unconfirmed fix is to add the following line:

nanoseconds &= ~NegativeBit;

after the line:

var isNegative = (nanoseconds & NegativeBit) != 0;

in the TryToTimeSpan method in both classes.

Steps to reproduce

  1. Simply call Iso8601Duration.TryParse("-P1D", out var ts) and compare ts with TimeSpan.FromDays(-1).

Relevant log output

No response

Additional Context?

No response

Product

Hot Chocolate

Version

12.9.0

@ghost ghost added the 🐛 bug label May 17, 2022
@PascalSenn
Copy link
Member

@celerum-deryck thanks for reporting :)
Do you want to make a pull request?

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 a pull request may close this issue.

2 participants