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

[DE DateTimeV2] Duration issue with double numbers due to incorrect toString call #3053

Open
stegreiwe opened this issue Dec 5, 2022 · 2 comments
Labels

Comments

@stegreiwe
Copy link

In the date time recognition seems to be a culture dependent issue in the calculation of a duration in System.Threading.Thread.CurrentThread.CurrentCulture = "de-DE" environments.

A german sentence "Wir haben anderthalb Stunden gewartet." > engl. "We waited one and a half hours." translates into a Timex PT15H, but
the result should be PT1.5H

In line 201 of the current BaseDurationParser.cs

numVal = double.Parse(pr.Value.ToString(), CultureInfo.InvariantCulture) + ParseNumberWithUnitAndSuffix(suffixStr);

pr.Value contains the correct double value of 1.5, but ToString() reformats this to "1,5" (with comma because of de-DE) and the invariant double.Parse makes 15 out of it in result.

When doing for example
var valueAsString = Convert.ToString(pr.Value, CultureInfo.InvariantCulture);
numVal = double.Parse(valueAsString, CultureInfo.InvariantCulture) + ParseNumberWithUnitAndSuffix(suffixStr);
instead,
numVal gets the correct value of 1.5, even when the threading culture is German

@tellarin
Copy link
Collaborator

tellarin commented Dec 6, 2022

@stegreiwe, thanks for catching this! Would you be able to create a PR with the corresponding fix and a test case showing the correct behaviour? If that's not possible, we'll try to add the fix ASAP.

@tellarin tellarin added the bug label Dec 6, 2022
@tellarin tellarin changed the title Duration issue with double numbers in BaseDurationParser.cs line 201 [DE DateTimeV2] Duration issue with double numbers due to incorrect toString call Dec 6, 2022
@stegreiwe
Copy link
Author

Oh, thx for recognizing this issue.

You do have the sentence already in your German test cases. That's where I got it from. Maybe it makes sense to change the Thread-Culture at the beginning of the tests. It would have been issued then directly from your test cases.

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

No branches or pull requests

2 participants