feat(config): add configurable date format

- Add dateFormat property to Config with ISO 8601 default
- Use config.dateFormat for both sample text and live clock
- Improve sample date generation to test edge case (UTC-12 timezone)
This commit is contained in:
2026-04-15 18:12:10 -04:00
parent 451bf3a9fc
commit 95d95840aa

View File

@@ -12,6 +12,7 @@ struct Config: Codable {
var position: Position = .top_right
var offsetX: Double = 0.0
var offsetY: Double = 0.0
var dateFormat: String = "yyyy-MM-dd'T'HH:mm:ssXXXXX"
}
func loadConfig() -> Config {
@@ -65,7 +66,21 @@ label.alignment = .center
label.translatesAutoresizingMaskIntoConstraints = false
// Sample Dimensions
let sampleText = "2026-04-15T23:59:59+00:00"
let sampleFormatter = DateFormatter()
sampleFormatter.dateFormat = config.dateFormat
sampleFormatter.locale = Locale(identifier: "en_US_POSIX")
let sampleDate = {
var components = DateComponents()
components.year = 2026
components.month = 12
components.day = 30
components.hour = 23
components.minute = 59
components.second = 59
components.timeZone = TimeZone(secondsFromGMT: -12 * 3600) // Widest offset
return Calendar.current.date(from: components) ?? Date()
}()
let sampleText = sampleFormatter.string(from: sampleDate)
let textSize = (sampleText as NSString).size(withAttributes: [.font: font])
let windowSize = NSSize(
width: ceil(textSize.width + config.horizontalPadding * 2),
@@ -135,7 +150,7 @@ window.contentView = vfx
window.orderFrontRegardless()
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssXXXXX"
formatter.dateFormat = config.dateFormat
formatter.locale = Locale(identifier: "en_US_POSIX")
func updateClock() {