diff --git a/Kit/extensions.swift b/Kit/extensions.swift index 4c21a505..7432e80a 100644 --- a/Kit/extensions.swift +++ b/Kit/extensions.swift @@ -550,13 +550,18 @@ public extension Date { } public extension TimeZone { - init(fromUTC: String) { - if fromUTC == "local" { + init(from: String) { + if let tz = TimeZone(identifier: from) { + self = tz + return + } + + if from == "local" { self = TimeZone.current return } - let arr = fromUTC.split(separator: ":") + let arr = from.split(separator: ":") guard !arr.isEmpty else { self = TimeZone.current return diff --git a/Modules/Clock/main.swift b/Modules/Clock/main.swift index b7cc1c9d..1e240bc4 100644 --- a/Modules/Clock/main.swift +++ b/Modules/Clock/main.swift @@ -42,7 +42,7 @@ public struct Clock_t: Codable { public func formatted() -> String { let formatter = DateFormatter() formatter.dateFormat = self.format - formatter.timeZone = TimeZone(fromUTC: self.tz) + formatter.timeZone = TimeZone(from: self.tz) return formatter.string(from: self.value ?? Date()) } } @@ -159,7 +159,8 @@ extension Clock { KeyValue_t(key: "11", value: "UTC+11:00"), KeyValue_t(key: "12", value: "UTC+12:00"), KeyValue_t(key: "13", value: "UTC+13:00"), - KeyValue_t(key: "14", value: "UTC+14:00") - ] + KeyValue_t(key: "14", value: "UTC+14:00"), + KeyValue_t(key: "separator", value: "separator") + ] + TimeZone.knownTimeZoneIdentifiers.map { KeyValue_t(key: $0, value: $0) } } } diff --git a/Modules/Clock/popup.swift b/Modules/Clock/popup.swift index df573d68..561e0286 100644 --- a/Modules/Clock/popup.swift +++ b/Modules/Clock/popup.swift @@ -499,7 +499,7 @@ private class ClockView: NSStackView { if (self.window?.isVisible ?? false) || !self.ready { self.timeField.stringValue = newClock.formatted() if let value = newClock.value { - self.clockView.setValue(value.convertToTimeZone(TimeZone(fromUTC: newClock.tz))) + self.clockView.setValue(value.convertToTimeZone(TimeZone(from: newClock.tz))) } self.ready = true } diff --git a/Modules/Clock/portal.swift b/Modules/Clock/portal.swift index cd88681e..3464bff1 100644 --- a/Modules/Clock/portal.swift +++ b/Modules/Clock/portal.swift @@ -80,7 +80,7 @@ public class Portal: NSStackView, Portal_p { let views = self.oneContainer.subviews.compactMap{ $0 as? ClockChart } if let view = views.first(where: { $0.identifier?.rawValue == clock.id }) { if let value = clock.value { - view.setValue(value.convertToTimeZone(TimeZone(fromUTC: clock.tz))) + view.setValue(value.convertToTimeZone(TimeZone(from: clock.tz))) } } else { self.oneContainer.addRow(with: [self.clockView(clock)]) @@ -102,7 +102,7 @@ public class Portal: NSStackView, Portal_p { sorted.forEach { (c: Clock_t) in if let view = views.first(where: { $0.identifier?.rawValue == c.id }) { if let value = c.value { - view.setValue(value.convertToTimeZone(TimeZone(fromUTC: c.tz))) + view.setValue(value.convertToTimeZone(TimeZone(from: c.tz))) } } else { self.multiplyContainer.stackView.addArrangedSubview(clockView(c)) @@ -117,7 +117,7 @@ public class Portal: NSStackView, Portal_p { view.identifier = NSUserInterfaceItemIdentifier(clock.id) if let value = clock.value { - view.setValue(value.convertToTimeZone(TimeZone(fromUTC: clock.tz))) + view.setValue(value.convertToTimeZone(TimeZone(from: clock.tz))) } return view diff --git a/Modules/Clock/settings.swift b/Modules/Clock/settings.swift index 99508bd2..42c4d4f3 100644 --- a/Modules/Clock/settings.swift +++ b/Modules/Clock/settings.swift @@ -204,6 +204,9 @@ internal class Settings: NSStackView, Settings_v, NSTableViewDelegate, NSTableVi let select: NSPopUpButton = selectView(action: #selector(self.toggleTZ), items: Clock.zones, selected: item.tz) select.identifier = NSUserInterfaceItemIdentifier("\(row)") select.sizeToFit() + select.preferredEdge = .maxX + select.translatesAutoresizingMaskIntoConstraints = false + select.widthAnchor.constraint(lessThanOrEqualToConstant: 132).isActive = true cell.addSubview(select) case statusColumnID: let button: NSButton = NSButton(frame: NSRect(x: 0, y: 5, width: 10, height: 10))