You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PowerShell 7: reset times shifted by UTC offset and day/month swapped on non-US locales #57
When statusline.ps1 runs under PowerShell 7 (pwsh, as recommended in INSTALL.md), the 5h and 7d reset times are wrong on a non-US locale. Under Windows PowerShell 5.1 the same script shows the correct values.
Windows 11, PowerShell 7.6.6 vs Windows PowerShell 5.1
Culture: pl-PL, time zone UTC+2 (CEST)
Actual vs expected
PowerShell 5.1 (correct)
PowerShell 7 (wrong)
5h reset
@5:00pm
@3:00pm (shifted by the UTC offset)
7d reset
@fri oct 9, 9:00am
@thu sep 10, 7:00am (day and month swapped, plus the UTC shift)
Cause
In PowerShell 7, ConvertFrom-Json automatically converts ISO 8601 strings such as resets_at into [DateTime] objects. Windows PowerShell 5.1 leaves them as strings.
Format-ResetTime declares the parameter as [string]$isoStr, so the DateTime is converted back into a string. PowerShell uses the invariant culture for this conversion (10/09/2026 15:00:00, MM/dd) and drops the UTC kind. Then [DateTimeOffset]::Parse($isoStr) parses that string with the current culture. Under pl-PL (dd.MM) this swaps day and month, and the time is read as local time instead of UTC.
Suggested fix
-function Format-ResetTime([string]$isoStr, [string]$style) {+function Format-ResetTime([object]$isoStr, [string]$style) {
if (-not $isoStr -or $isoStr -eq "null") { return $null }
try {
- $dt = [DateTimeOffset]::Parse($isoStr).LocalDateTime+ # PowerShell 7's ConvertFrom-Json already turns ISO strings into DateTime;+ # stringifying it again loses UTC and swaps day/month under non-US cultures.+ $dt = if ($isoStr -is [DateTime]) { $isoStr.ToLocalTime() }+ elseif ($isoStr -is [DateTimeOffset]) { $isoStr.LocalDateTime }+ else { [DateTimeOffset]::Parse([string]$isoStr, [Globalization.CultureInfo]::InvariantCulture).LocalDateTime }
With this change, both pwsh and powershell produce identical, correct output on pl-PL.
The fix keeps PowerShell 5.1 compatibility. In PowerShell 7.5+ you could instead use ConvertFrom-Json -DateKind String, but 5.1 does not support that parameter.
Activity