Files
Claude Fable 5 a0ff61ae14 feat(dubai-time): add checkTime formatter for HH:MM Dubai timestamps
Manual update checks now display the time checked in Dubai timezone.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ZiTXPbPCSjzPVsfoweAbp
2026-09-05 11:01:15 +04:00

46 lines
1.6 KiB
Swift

import Foundation
public enum DubaiTime {
private static let stampFormatter = LockedDateFormatter(dateFormat: "d MMM yyyy, HH:mm 'Dubai'")
private static let fileStampFormatter = LockedDateFormatter(dateFormat: "yyyyMMdd-HHmmss")
private static let checkTimeFormatter = LockedDateFormatter(dateFormat: "HH:mm 'Dubai'")
public static func stamp(_ date: Date) -> String {
stampFormatter.string(from: date)
}
public static func fileStamp(_ date: Date) -> String {
fileStampFormatter.string(from: date)
}
public static func checkTime(_ date: Date) -> String {
checkTimeFormatter.string(from: date)
}
}
/// DateFormatter is not Sendable. This holder is the only shared mutable state
/// around a formatter: every read is serialized by the lock, so concurrent
/// calls (one per PDF page) cannot race.
private final class LockedDateFormatter: @unchecked Sendable {
private let lock = NSLock()
private let formatter: DateFormatter
init(dateFormat: String) {
let formatter = DateFormatter()
formatter.calendar = Calendar(identifier: .gregorian)
formatter.locale = Locale(identifier: "en_GB")
guard let dubai = TimeZone(identifier: "Asia/Dubai") else {
preconditionFailure("The Asia/Dubai time zone is missing from this system.")
}
formatter.timeZone = dubai
formatter.dateFormat = dateFormat
self.formatter = formatter
}
func string(from date: Date) -> String {
lock.lock()
defer { lock.unlock() }
return formatter.string(from: date)
}
}