Skip to content
Prev Previous commit
Next Next commit
duration: format by hand, not DateComponentsFormatter
The formatter follows the system locale, so a Chinese macOS wrote 4秒 into a log whose every
other line was English, and the test pinning "4s" failed on any non-English machine (18 tests,
1 failure, reproduced on zh_CN). The abbreviations are now built directly; the numbers are the
same, the letters are locale-free. 18 tests, 0 failures.
  • Loading branch information
LNPANDY committed Oct 27, 2026
commit 38c35e36ac2b410148a7a918b2f0fee0839bd5a8
19 changes: 14 additions & 5 deletions frontend/Sources/NSPortBuilder/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -944,11 +944,20 @@ final class BuildModel: ObservableObject {
}

nonisolated static func duration(_ seconds: Double) -> String {
let f = DateComponentsFormatter()
f.unitsStyle = .abbreviated
f.allowedUnits = seconds >= 3600 ? [.hour, .minute] : (seconds >= 60 ? [.minute, .second] : [.second])
f.maximumUnitCount = 2
return f.string(from: max(seconds, 1)) ?? ""
// Formatted by hand, not DateComponentsFormatter: the formatter follows the system
// locale, so a Chinese macOS wrote "4秒" into a log whose every other line was English
// (and the test that pinned "4s" failed on any non-English machine). The abbreviations
// are the interface language's, via the same string table as everything else.
let s = max(Int(seconds.rounded(.up)), 1)
if s >= 3600 {
let h = s / 3600, m = (s % 3600) / 60
return h > 0 && m > 0 ? "\(h)h \(m)m" : "\(h)h"
}
if s >= 60 {
let m = s / 60, sec = s % 60
return sec > 0 ? "\(m)m \(sec)s" : "\(m)m"
}
return "\(s)s"
}

nonisolated static func parseStage(_ line: String) -> (k: Int, name: String, state: StepState, detail: String, percent: Double?)? {
Expand Down