Fix LastChecked date corruption on non-US locales (parse/format with InvariantCulture)#42
Open
anagnorisis2peripeteia wants to merge 1 commit into
Conversation
LastCheckString wrote the date as MM/dd/yyyy (month-first) but read it back with a culture-dependent DateTime.TryParse. On non-US locales the read interprets MM/dd as dd/MM, so a saved LastChecked round-trips to the wrong date (month and day swapped) - a settings file's date breaks when read on a machine with a different locale. Use CultureInfo.InvariantCulture for both the format and the parse so the value round-trips consistently regardless of the machine's culture. Also make the CheckSettingsRead assertion's parse culture-invariant so it passes on non-US locales (it currently fails on e.g. en-GB).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AppSettingsDTO.LastCheckStringwrites theLastCheckeddate asMM/dd/yyyy(month-first) but reads it back with a culture-dependentDateTime.TryParse. On a non-US locale the parse readsMM/ddasdd/MM, so a savedLastCheckedround-trips to the wrong date — month and day swapped. A settings file written on one machine gets a corruptedLastCheckedwhen read on a machine with a different locale.Fix: use
CultureInfo.InvariantCulturefor both the format and the parse, so the value round-trips consistently regardless of the machine's culture. I also made the existingCheckSettingsReadassertion's own parse culture-invariant — it currently fails on non-US locales because it re-parses the value with the current culture.Before/after (on an
en-GBmachine):CheckSettingsReadfails —Assert.AreEqual failed. Expected:<05/12/2023 00:24:15>. Actual:<12/05/2023 00:24:15>.(month/day swapped on round-trip).CheckSettingsReadpasses; the full test suite (with the repo's documented CI exclusions) is green — 12/12.A normal US-locale CI run doesn't surface this, which is why it's gone unnoticed.
Local review history: https://gist.github.com/e1d6299912b5f55dba818b128290b2bb
Proof manifest
Structured before/after manifest for the red-green evidence already in this description (CheckSettingsRead fails on en-GB before, passes after; full suite 12/12 after).
Manifest + raw run outputs: https://gist.github.com/anagnorisis2peripeteia/362f9cb73c6c229d9eb1b04a4e7d9bb4