Skip to content

Instantly share code, notes, and snippets.

@atierian
Created February 22, 2021 22:01
Show Gist options
  • Select an option

  • Save atierian/09e55452701dcfeeef82f73c6a65b3f3 to your computer and use it in GitHub Desktop.

Select an option

Save atierian/09e55452701dcfeeef82f73c6a65b3f3 to your computer and use it in GitHub Desktop.
TimeZones Split by Daylight Savings Time Participants
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