Skip to content

fix: truncate hours in countdowns instead of rounding them - #2

Open
knightmare2600 wants to merge 1 commit into
PowerShellYoungTeam:mainfrom
knightmare2600:pr/fix-countdown-hours
Open

knightmare2600 wants to merge 1 commit into
PowerShellYoungTeam:mainfrom
knightmare2600:pr/fix-countdown-hours

Conversation

@knightmare2600

@knightmare2600 knightmare2600 commented Oct 9, 2026 •

Copy link
Copy Markdown

Summary

Countdowns rounded the hours component instead of truncating it, so they could be an hour too high.

The bug

  • Every countdown formatted hours with [int]$TimeSpan.TotalHours. PowerShell's [int] cast rounds to nearest (ties to even); it does not truncate. Reproduction:
    [int]7.6   # 8
    [int]2.5   # 2
    [int]3.5   # 4
  • So 7 h 36 m until the open (TotalHours = 7.6) was displayed as 08:36:00.

The fix

  • Use [int][math]::Floor($TimeSpan.TotalHours) in all five countdown formatters:
    • pre-market "Opens in …"
    • lunch break "Reopens in …"
    • "Closes in …"
    • the DataGrid countdown column
    • the status-bar next-close countdown
  • No other behaviour changes. The "N h ago" relative-time label (Format-RelativeTime) is not a countdown and is left as is.

Interaction with other PRs

#5 (Nasdaq Copenhagen) moves these same lines into a shared Format-CountdownSpan helper that also truncates. If both are merged, the second one conflicts on these lines — keep #5's version.

Checks

  • Parses cleanly; manifest validates.
  • Lint: the Lint workflow already fails on main before this change — PSScriptAnalyzer reports 120 Warning-level findings there (e.g. run 36486962685). This PR adds no new findings (compared by rule, file and message against main), so a red Lint check here is the pre-existing state.
  • Not run: the WPF dashboard itself (Windows-only); checks were run on Linux with PowerShell 7.6.3.
  • CHANGELOG: this PR adds its own entry under [Unreleased]. The PRs in this series are independent where possible, so whichever merges second will have a trivial conflict in that section — keep both entries.

This is one of a series of small PRs (fixes and features kept separate so you can pick and choose): #2 countdown hours · #3 Refresh button · #4 map preferences · #5 Nasdaq Copenhagen · #6 OMXC25 · #7 FX DKK/SEK · #8 København clock · #9 FTSE 100 · #10 ETF labels.

🤖 Generated with Claude Code

PowerShell's [int] cast rounds to nearest, so a TimeSpan of 7h36m
(TotalHours 7.6) was formatted as "08:36:00". Use [math]::Floor for
the hours component in all five countdown formatters: pre-market,
lunch break, closing, the DataGrid countdown column and the status-bar
next-close countdown.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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