Created
February 22, 2021 22:01
-
-
Save atierian/09e55452701dcfeeef82f73c6a65b3f3 to your computer and use it in GitHub Desktop.
TimeZones Split by Daylight Savings Time Participants
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct TimeZoneDisplay { | |
| struct TimeZone { | |
| let abbreviation: String | |
| let description: String | |
| let isDaylightSavingsParticipant: Bool | |
| } | |
| var timeZones = [TimeZone]() | |
| init(_ systemZones: Dictionary<String, String> = NSTimeZone.abbreviationDictionary) { | |
| timeZones = systemZones.map { | |
| TimeZone( | |
| abbreviation: $0.key, | |
| description: $0.value, | |
| isDaylightSavingsParticipant: NSTimeZone( | |
| abbreviation: $0.key)? | |
| .nextDaylightSavingTimeTransition != nil | |
| ) | |
| } | |
| } | |
| lazy var participants = timeZones.filter { $0.isDaylightSavingsParticipant } | |
| lazy var nonParticipants = timeZones.filter { !$0.isDaylightSavingsParticipant } | |
| } | |
| let timeZoneDisplay = TimeZoneDisplay() | |
| print("PARTICPANTS") | |
| print(timeZoneDisplay.participants.map { $0.abbreviation }) | |
| print("NON-PARTICPANTS") | |
| print(timeZoneDisplay.nonParticipants.map { $0.abbreviation }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment