mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: added missing time zones to the clock
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user