Skip to content

Fix LastChecked date corruption on non-US locales (parse/format with InvariantCulture)#42

Open
anagnorisis2peripeteia wants to merge 1 commit into
hbashton:mainfrom
anagnorisis2peripeteia:fix/lastchecked-culture-invariant
Open

Fix LastChecked date corruption on non-US locales (parse/format with InvariantCulture)#42
anagnorisis2peripeteia wants to merge 1 commit into
hbashton:mainfrom
anagnorisis2peripeteia:fix/lastchecked-culture-invariant

Conversation

@anagnorisis2peripeteia

@anagnorisis2peripeteia anagnorisis2peripeteia commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

AppSettingsDTO.LastCheckString writes the LastChecked date as MM/dd/yyyy (month-first) but reads it back with a culture-dependent DateTime.TryParse. On a non-US locale the parse reads MM/dd as dd/MM, so a saved LastChecked round-trips to the wrong date — month and day swapped. A settings file written on one machine gets a corrupted LastChecked when read on a machine with a different locale.

Fix: use CultureInfo.InvariantCulture for both the format and the parse, so the value round-trips consistently regardless of the machine's culture. I also made the existing CheckSettingsRead assertion'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-GB machine):

  • Before: CheckSettingsRead fails — Assert.AreEqual failed. Expected:<05/12/2023 00:24:15>. Actual:<12/05/2023 00:24:15>. (month/day swapped on round-trip).
  • After: CheckSettingsRead passes; 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

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).
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 this pull request may close these issues.

1 participant