sillsdev / sillsdev/SIL.BuildTasks

FileUpdate date insertion produces machine-dependent output (and 6 tests fail) when regional settings override the date separator

Open Beginner friendly
#91 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C#
Stars
5
Forks
3
Avg merge
1d 3h
Merged PRs (30d)
12

Description

Summary

FileUpdate formats dates with CultureInfo.CurrentCulture (FileUpdate.cs:120), which picks up Windows per-user regional customizations. Because / in a .NET custom date format string is a separator placeholder rather than a literal, any DateFormat containing / renders differently depending on the machine's regional settings.

This affects the task's own default format, dd/MMM/yyyy.

Reproduction

Set the Windows short date format to yyyy-MM-dd (Settings -> Time & language -> Language & region -> Regional format -> Change formats), leaving the culture at en-US. Then:

CurrentCulture   : en-US
DateSeparator    : '-'
ShortDatePattern : yyyy-MM-dd

(2026-04-16).ToString("dd/MMM/yyyy", CurrentCulture)   -> 16-Apr-2026
(2026-04-16).ToString("dd/MMM/yyyy", InvariantCulture) -> 16/Apr/2026

dotnet test SIL.BuildTasks.Tests then fails 6 tests in FileUpdateTests — every case whose expected value contains a literal /:

  • GetModifiedContents_DateLiteral_InsertsDateWithSpecifiedDateFormat (3 cases)
  • GetModifiedContents_SpecialDatePlaceholderButFileDoesNotSpecifyFormat_InsertsDateWithSpecifiedDateFormat (1 case)
  • GetModifiedContents_SpecialDatePlaceholderWithFileSpecifyingMultipleFormats_InsertsDateWithFormatsFromFile (2 cases)

Cases using - as the separator (dd-MM-yy, MM-yyyy) pass, since - is a literal in custom format strings. CI passes because the runners use default regional settings.

Impact

Build output is not reproducible across machines. A developer or CI agent with customized regional settings writes a different date into release notes, installers, or any other file FileUpdate touches, with no warning. The default DateFormat is affected, so a project need not opt into anything unusual to hit this.

The same applies to : in a format string, which is the time separator placeholder, and which the placeholder regex at FileUpdate.cs:126 explicitly permits.

Suggested fix

Construct the culture with user overrides disabled, which keeps localized month names working (the point of FileLocalePattern) while making separators depend only on the culture identity:

var culture = GetCultureFromFileName()
    ?? new CultureInfo(CultureInfo.CurrentCulture.Name, useUserOverride: false);

Verified on the affected machine:

Culture dd/MMM/yyyy d MMMM yyyy
CurrentCulture (overrides on) 16-Apr-2026
same name, useUserOverride: false 16/Apr/2026
new CultureInfo("fr", false) 16 avril 2026

FileUpdate.cs:165 has the same exposure: new CultureInfo(locale) honors user overrides when locale matches the machine's default culture, so it should pass useUserOverride: false too.

Also worth tidying

GetModifiedContents_SpecialDatePlaceholderWithFileSpecifyingMultipleFormats_InsertsDateWithFormatsFromFile is internally inconsistent — it computes two expected segments via ToString(format) (which tracks the culture) but hardcodes the middle one as 16/Apr/2026 (FileUpdateTests.cs:157). That is why only part of the assertion fails. Once the fix lands, a test pinning the culture explicitly would catch regressions regardless of the runner's regional settings.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in SIL.BuildTasks/FileUpdate.cs at the date-formatting code around lines 120, 126, and 165, then review the six named cases in SIL.BuildTasks.Tests/FileUpdateTests.cs. Run dotnet test SIL.BuildTasks.Tests with customized regional settings and pin the culture behavior so separators are stable while localized month names remain supported. Done means the affected tests pass consistently across regional settings.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
build-system
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
88/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.