You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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
The text was updated successfully, but these errors were encountered:
@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
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
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.
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
The text was updated successfully, but these errors were encountered: