Skip to content

Commit 93b1609

Browse files
fix: apply InvariantCulture DateTime formatting to fix Windows CI
The test 'series with datetime keys preserves time in Format' was failing on Windows because DateTime.ToString() uses the locale's AM/PM format. Apply the same fix as PR #643: use 'yyyy-MM-dd HH:mm:ss' with InvariantCulture for DateTime keys that have a non-zero time component. Co-authored-by: Copilot <[email protected]>
1 parent e08a288 commit 93b1609

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/Deedle/Common/Common.fs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1433,11 +1433,15 @@ module Formatting =
14331433

14341434
/// Format a key value for display. DateTime keys with no time component (i.e. time = 00:00:00)
14351435
/// are formatted as date-only using the current culture's short date format, matching the
1436-
/// behaviour of SaveCsv. All other values are formatted with ToString().
1436+
/// behaviour of SaveCsv. DateTime keys with a time component are formatted as
1437+
/// "yyyy-MM-dd HH:mm:ss" using the invariant culture to ensure consistent output
1438+
/// across locales (e.g. avoiding AM/PM suffixes on Windows). All other values use ToString().
14371439
let formatKey (key:obj) =
14381440
match key with
14391441
| :? DateTime as dt when dt.TimeOfDay = TimeSpan.Zero ->
14401442
dt.ToString("d", Globalization.CultureInfo.CurrentCulture)
1443+
| :? DateTime as dt ->
1444+
dt.ToString("yyyy-MM-dd HH:mm:ss", Globalization.CultureInfo.InvariantCulture)
14411445
| _ -> key.ToString()
14421446

14431447
let formatTable (data:string[,]) =

tests/Deedle.Tests/Formatting.fs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,15 @@ let ``series with date-only DateTime keys omits time in Format`` () =
285285

286286
[<Test>]
287287
let ``series with datetime keys preserves time in Format`` () =
288-
// Keys with a non-zero time component should still include the time.
288+
// Keys with a non-zero time component are formatted as "yyyy-MM-dd HH:mm:ss" (invariant, no AM/PM).
289289
let s = series [
290290
DateTime(2023, 1, 1, 9, 30, 0) => 1.0
291291
DateTime(2023, 1, 1, 10, 0, 0) => 2.0 ]
292292
let fmt = s.Format()
293-
fmt |> should contain "09:30:00"
293+
fmt |> should contain "2023-01-01 09:30:00"
294+
fmt |> should contain "2023-01-01 10:00:00"
295+
fmt |> should (contain >> not') "AM"
296+
fmt |> should (contain >> not') "PM"
294297

295298
[<Test>]
296299
let ``series ToString with date-only DateTime keys omits time`` () =

0 commit comments

Comments
 (0)