Skip to content

Instantly share code, notes, and snippets.

@benbahrenburg
Created December 29, 2019 04:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save benbahrenburg/ffccf867e3924f447c6af4278db7efc6 to your computer and use it in GitHub Desktop.
Save benbahrenburg/ffccf867e3924f447c6af4278db7efc6 to your computer and use it in GitHub Desktop.
List all iOS timezones
class TimeZoneManager {
static let shared = TimeZoneManager()
private init() {}
private var continents = [String]()
private var timeZonesList = [String: [String]]()
var timeZones: [String: [String]] {
get {
for timeZone in TimeZone.knownTimeZoneIdentifiers {
let continent = timeZone.components(separatedBy: "/")[0]
if !continents.contains(continent) {
continents.append(continent)
}
var timeZonesInContinent = timeZonesList[continent] ?? [String]()
if let zone = timeZone.components(separatedBy: "/").last {
if !timeZonesInContinent.contains(zone) {
timeZonesInContinent.append(zone)
}
}
timeZonesList[continent] = timeZonesInContinent
}
return timeZonesList
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment