+semver:major Made ParseDateTimePermissivelyWithException into an extension method#1422
+semver:major Made ParseDateTimePermissivelyWithException into an extension method#1422
Conversation
…ension method Added test cases for ToISO8601TimeFormatWithUTCString and some unit tests for Made ParseDateTimePermissivelyWithException
Palaso Tests 4 files ± 0 4 suites ±0 10m 44s ⏱️ - 9m 11s Results for commit 2ec4327. ± Comparison against base commit 73469af. This pull request removes 4 and adds 42 tests. Note that renamed tests count towards both.This pull request removes 1 skipped test and adds 1 skipped test. Note that renamed tests count towards both.This pull request skips 1 test.♻️ This comment has been updated with latest results. |
imnasnainaec
left a comment
There was a problem hiding this comment.
Reviewed 3 of 3 files at r1, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @tombogle)
…teTimePermissivelyWithException to indicate an reasonable range of dates and changed behavior of the method to try to interpret the date according to either the Gregorian calendar or the Buddhist calender in order to get the date to fall within the reasonably expected range. Added more test cases
imnasnainaec
left a comment
There was a problem hiding this comment.
Reviewed all commit messages.
Reviewable status: 0 of 6 files reviewed, 2 unresolved discussions (waiting on @tombogle)
SIL.Core/Extensions/DateTimeExtensions.cs line 106 at r2 (raw file):
/// </summary> public static DateTime ParseDateTimePermissivelyWithException(this string when, int oldestReasonablyExpectedYear = 1900, int numberOfDaysIntoFutureReasonablyExpected = 1)
numberOfDaysIntoFutureReasonablyExpected = 1 assumes that somebody isn't commonly using this date-time parsing in event/calendar planning settings. In case somebody is, then having the unit be days instead of years is awkward. Would something like numberOfYearsIntoFutureReasonablyExpected = 10 not work well with the new implementation?
CHANGELOG.md line 70 at r2 (raw file):
- [SIL.Core] Improved efficiency in XmlUtils methods: MakeSafeXml and ConvertMultiParagraphToSafeXml (name corrected), and MakeSafeXmlAttribute. - [SIL.Core] BREAKING CHANGE (potentially): Made ParseDateTimePermissivelyWithException into an extension method (on string). - [SIL.Core] BREAKING CHANGE (potentially): Added optional parameters to DateTimeExtensions.ParseDateTimePermissivelyWithException: `oldestReasonablyExpectedYear` and `numberOfDaysIntoFutureReasonablyExpected`. Also, changed behavior of this method to try to interpret the date according to either the Gregorian calendar or the Buddhist calender in order to get the date to fall within the reasonably expected range. This means that depending on the current culture, dates might be interpreted differently from before.
The CHANGELOG entry should probably mention what the default values are for new optional parameters.
SIL.Core.Tests/IO/FileLocationUtilitiesTests.cs line 114 at r2 (raw file):
[Test] public void LocateInProgramFiles_SendInValidSubFolder_DoesNotThrow()
InValid -> Invalid
SIL.Core.Tests/IO/FileLocationUtilitiesTests.cs line 236 at r2 (raw file):
[Test] public void LocateExecutable_NonexistentFileFileThrows()
FileFileThrows -> FileThrows
TestApps/CommandLineRunnerTestApp/CommandLineRunnerTestApp.csproj line 10 at r2 (raw file):
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <TargetFrameworks>$(TargetFrameworks);net8.0</TargetFrameworks> <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
Why is this the only test app that needs GenerateRuntimeConfigurationFiles?
.github/workflows/build.yml line 82 at r2 (raw file):
id: test run: dotnet test "$TEST_PATH"/SIL*Tests.dll --filter "(TestCategory != SkipOnTeamCity) & (TestCategory != RequiresAudioInputDevice)" --blame-hang-timeout 5m --logger:"trx;LogFilePrefix=results" --results-directory ./test-results
whitespace on this empty line
…tion and added three alternative versions whose names more clearly indicate their behavior. Minor code cleanup in response to code review.
tombogle
left a comment
There was a problem hiding this comment.
Reviewable status: 0 of 6 files reviewed, 1 unresolved discussion (waiting on @imnasnainaec and @tombogle)
CHANGELOG.md line 70 at r2 (raw file):
Previously, imnasnainaec (D. Ror.) wrote…
The CHANGELOG entry should probably mention what the default values are for new optional parameters.
Done
.github/workflows/build.yml line 82 at r2 (raw file):
Previously, imnasnainaec (D. Ror.) wrote…
whitespace on this empty line
Fixed
SIL.Core/Extensions/DateTimeExtensions.cs line 106 at r2 (raw file):
Previously, imnasnainaec (D. Ror.) wrote…
numberOfDaysIntoFutureReasonablyExpected = 1assumes that somebody isn't commonly using this date-time parsing in event/calendar planning settings. In case somebody is, then having the unit be days instead of years is awkward. Would something likenumberOfYearsIntoFutureReasonablyExpected = 10not work well with the new implementation?
In both places I know of where this is currently being used, it is for dates that are typically in the past but usually for relatively recent (modern times) event. Hence the defaults. The reason I wanted to go 1 day into the future was to avoid weird off-by-one issues with time zones. I agree that it looks weirdly inconsistent to use a year for the past and a day offset for the future. I considered the alternative of using an actual DateTime for both, but a) it is impossible to use DateTimes as default values, and b) it felt onerous to require the existing implementations to calculate and supply useful dates. I have decided to deprecate the original version and supply three alternative versions whose names more clearly indicate their behavior.
SIL.Core.Tests/IO/FileLocationUtilitiesTests.cs line 114 at r2 (raw file):
Previously, imnasnainaec (D. Ror.) wrote…
InValid -> Invalid
Fixed
SIL.Core.Tests/IO/FileLocationUtilitiesTests.cs line 236 at r2 (raw file):
Previously, imnasnainaec (D. Ror.) wrote…
FileFileThrows -> FileThrows
Fixed
TestApps/CommandLineRunnerTestApp/CommandLineRunnerTestApp.csproj line 10 at r2 (raw file):
Previously, imnasnainaec (D. Ror.) wrote…
Why is this the only test app that needs
GenerateRuntimeConfigurationFiles?
It gets run as part of the unit tests. It was failing, and ChatGPT said that adding that would solve the problem (and it did).
imnasnainaec
left a comment
There was a problem hiding this comment.
Reviewed 1 of 6 files at r2, 1 of 5 files at r3, all commit messages.
Reviewable status: 2 of 6 files reviewed, 3 unresolved discussions (waiting on @tombogle)
SIL.Core.Tests/Extensions/DateTimeExtensionTests.cs line 192 at r3 (raw file):
/// <param name="expectedResultFormattedAsBuddhistDate"></param> [TestCase("9/3/2025 0:00:00", true, "9/3/2568")] [TestCase("2-2-1920", true, "2/2/2463")] //
stray // at the end of this line
SIL.Core.Tests/Extensions/DateTimeExtensionTests.cs line 234 at r3 (raw file):
/// <summary> /// For these test cases, well will supply a future date (beyond reasonableMax) and pass
"well will" -> "we will" here and in several other <summary>s
CHANGELOG.md line 32 at r3 (raw file):
- [SIL.Core] Added correctly spelled XmlUtils.ConvertMultiParagraphToSafeXml. - [SIL.Core] Added DateTimeExtensions.ParseModernPastDateTimePermissivelyWithException (as the most probable replacement for the deprecated version of ParseDateTimePermissivelyWithException). - [SIL.Core] Added DateTimeExtensions.ParsePastDateTimePermissivelyWithException as a convenience method.
"convenience method" ParsePastDateTimePermissivelyWithException feels like it may be overkill. Unless you have planned use for it, I think it's just adding to maintenance burden.
SIL.Core.Tests/IO/FileLocationUtilitiesTests.cs line 92 at r3 (raw file):
} [Test] // On CI build (GHA) this can time out
// On CI build (GHA) this can time out shows up twice on this test and only once in the test above
tombogle
left a comment
There was a problem hiding this comment.
Reviewable status: 2 of 6 files reviewed, 3 unresolved discussions (waiting on @imnasnainaec)
CHANGELOG.md line 32 at r3 (raw file):
Previously, imnasnainaec (D. Ror.) wrote…
"convenience method"
ParsePastDateTimePermissivelyWithExceptionfeels like it may be overkill. Unless you have planned use for it, I think it's just adding to maintenance burden.
Maybe, but I felt like its presence might help to shed some light on the other options. I'm not 100% sure how/why the Combine uses this, and I wanted to try to provide a possibly easier way forward in case their situation is somewhat different from SayMore.
tombogle
left a comment
There was a problem hiding this comment.
Reviewable status: 2 of 6 files reviewed, 3 unresolved discussions (waiting on @imnasnainaec and @tombogle)
SIL.Core.Tests/Extensions/DateTimeExtensionTests.cs line 192 at r3 (raw file):
Previously, imnasnainaec (D. Ror.) wrote…
stray
//at the end of this line
Fixed
SIL.Core.Tests/Extensions/DateTimeExtensionTests.cs line 234 at r3 (raw file):
Previously, imnasnainaec (D. Ror.) wrote…
"well will" -> "we will" here and in several other
<summary>s
Fixed
SIL.Core.Tests/IO/FileLocationUtilitiesTests.cs line 92 at r3 (raw file):
Previously, imnasnainaec (D. Ror.) wrote…
// On CI build (GHA) this can time outshows up twice on this test and only once in the test above
Fixed
This is kind of related to SP-2356, though it's not yet clear whether any actual logic changes will be needed in these date-handling methods.
Added test cases for ToISO8601TimeFormatWithUTCString and some unit tests for Made ParseDateTimePermissivelyWithException
This change is