feat: added missing time zones to the clock

This commit is contained in:
Serhiy Mytrovtsiy
2023-04-04 18:56:10 +02:00
parent d79085fe4a
commit ac084bca28
2 changed files with 32 additions and 1 deletions

View File

@@ -602,7 +602,30 @@ public extension Date {
public extension TimeZone {
init(fromUTC: String) {
if let utc = Int(fromUTC), let tz = TimeZone(secondsFromGMT: utc*3600) {
if fromUTC == "local" {
self = TimeZone.current
return
}
let arr = fromUTC.split(separator: ":")
guard !arr.isEmpty else {
self = TimeZone.current
return
}
var secondsFromGMT = 0
if arr.indices.contains(0), let h = Int(arr[0]) {
secondsFromGMT += h*3600
}
if arr.indices.contains(1), let m = Int(arr[1]) {
if secondsFromGMT < 0 {
secondsFromGMT -= m*60
} else {
secondsFromGMT += m*60
}
}
if let tz = TimeZone(secondsFromGMT: secondsFromGMT) {
self = tz
} else {
self = TimeZone.current

View File

@@ -109,7 +109,9 @@ extension Clock {
KeyValue_t(key: "-7", value: "UTC-7:00"),
KeyValue_t(key: "-6", value: "UTC-6:00"),
KeyValue_t(key: "-5", value: "UTC-5:00"),
KeyValue_t(key: "-4:30", value: "UTC-4:30"),
KeyValue_t(key: "-4", value: "UTC-4:00"),
KeyValue_t(key: "-3:30", value: "UTC-3:30"),
KeyValue_t(key: "-3", value: "UTC-3:00"),
KeyValue_t(key: "-2", value: "UTC-2:00"),
KeyValue_t(key: "-1", value: "UTC-1:00"),
@@ -117,12 +119,18 @@ extension Clock {
KeyValue_t(key: "1", value: "UTC+1:00"),
KeyValue_t(key: "2", value: "UTC+2:00"),
KeyValue_t(key: "3", value: "UTC+3:00"),
KeyValue_t(key: "3:30", value: "UTC+3:30"),
KeyValue_t(key: "4", value: "UTC+4:00"),
KeyValue_t(key: "4:30", value: "UTC+4:30"),
KeyValue_t(key: "5", value: "UTC+5:00"),
KeyValue_t(key: "5:30", value: "UTC+5:30"),
KeyValue_t(key: "5:45", value: "UTC+5:45"),
KeyValue_t(key: "6", value: "UTC+6:00"),
KeyValue_t(key: "6:30", value: "UTC+6:30"),
KeyValue_t(key: "7", value: "UTC+7:00"),
KeyValue_t(key: "8", value: "UTC+8:00"),
KeyValue_t(key: "9", value: "UTC+9:00"),
KeyValue_t(key: "9:30", value: "UTC+9:30"),
KeyValue_t(key: "10", value: "UTC+10:00"),
KeyValue_t(key: "11", value: "UTC+11:00"),
KeyValue_t(key: "12", value: "UTC+12:00"),