Я ищу список часовых поясов, но когда я пытаюсь его сгенерировать, к нему добавляется смещение DST. Но я хочу стандартное время, а не с DST.
Вот код, который я использую. Для Дании я получаю GMT + 2 вместо GMT + 1
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .long
dateFormatter.timeStyle = .long
dateFormatter.dateFormat = "ZZZZ"
let list = TimeZone.knownTimeZoneIdentifiers
for (i, city) in list.enumerated() {
let timezone = TimeZone(identifier: city)
dateFormatter.timeZone = timezone
var isSupportDST = false
if timezone?.nextDaylightSavingTimeTransition != nil {
isSupportDST = true
}
let date = Date()
var timezoneString = dateFormatter.string(from: date)
if timezoneString.count > 3 {
timezoneString.insert(" ", at: timezoneString.index(timezoneString.startIndex, offsetBy: 3))
}
if timezoneString.count > 5 {
timezoneString.insert(" ", at: timezoneString.index(timezoneString.startIndex, offsetBy: 5))
}
var formattedCityName = city
formattedCityName = city.replacingOccurrences(of: "_", with: " ")
var dstoffset = 0 as TimeInterval
if let offset = timezone?.daylightSavingTimeOffset(){
dstoffset = offset
}
let cityWithTimezone = CityWithTimeZone(city: formattedCityName, timeZoneString: timezoneString, timeZoneInSeconds: timezone?.secondsFromGMT() ?? 0, dstOffset: dstoffset, isDSTSupport: isSupportDST)
cityList.insert(cityWithTimezone, at:i)
}