Skip to content

Commit 0060b07

Browse files
committed
Add some fudges for common time zones abbreviations that aren't included
1 parent 806e534 commit 0060b07

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

Elsewhen/Views/MykeMode.swift

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import SwiftUI
99

1010
struct MykeMode: View {
1111

12-
@State private var selectedDate: Date = Date(timeIntervalSince1970: TimeInterval(1631892600))
12+
@State private var selectedDate: Date = Date(timeIntervalSince1970: TimeInterval(1639239835))
13+
// @State private var selectedDate: Date = Date(timeIntervalSince1970: TimeInterval(1631892600))
1314
@State private var selectedTimeZones: [TimeZone] = [
1415
TimeZone(identifier: "America/Los_Angeles")!,
1516
TimeZone(identifier: "America/New_York")!,
@@ -37,7 +38,7 @@ struct MykeMode: View {
3738
HStack {
3839
Text("\(flagForTimeZone(tz)) \(selectedTimeInZone(tz))")
3940
Spacer()
40-
if let abbreviation = tz.abbreviation() {
41+
if let abbreviation = fudgedAbbreviation(for: tz) {
4142
Text(abbreviation)
4243
.foregroundColor(.secondary)
4344
}
@@ -54,6 +55,20 @@ struct MykeMode: View {
5455
selectedTimeZones.move(fromOffsets: source, toOffset: destination)
5556
}
5657

58+
func fudgedAbbreviation(for tz: TimeZone) -> String? {
59+
guard let abbreviation = tz.abbreviation(for: selectedDate) else { return nil }
60+
let isDaylightSavingTime = tz.isDaylightSavingTime(for: selectedDate)
61+
if tz.identifier == "Europe/London" && isDaylightSavingTime {
62+
return "BST"
63+
}
64+
if tz.identifier.starts(with: "Europe") {
65+
if isDaylightSavingTime && abbreviation == "GMT+2" || !isDaylightSavingTime && abbreviation == "GMT+1" {
66+
return "CET"
67+
}
68+
}
69+
return abbreviation
70+
}
71+
5772
}
5873

5974
struct MykeMode_Previews: PreviewProvider {

0 commit comments

Comments
 (0)