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