Skip to content

Instantly share code, notes, and snippets.

@romaHerman
Created February 27, 2017 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romaHerman/f119885591250a2dc5f0ebed8ac4b37f to your computer and use it in GitHub Desktop.
Save romaHerman/f119885591250a2dc5f0ebed8ac4b37f to your computer and use it in GitHub Desktop.
//: Playground - noun: a place where people can play
import UIKit
let formatter = DateFormatter()
formatter.dateFormat = "yyyy MM dd"
let date = formatter.date(from: "2017 03 31")
if let url = URL(string: "https://raw.githubusercontent.com/dmfilipenko/timezones.json/master/timezones.json") {
do {
let contents = try String(contentsOf: url)
let json = try JSONSerialization.jsonObject(with: contents.data(using: .utf8)!, options: .init(rawValue: 0))
if let timeZones = json as? [[String: Any]] {
for timeZone in timeZones {
if let utcArr = timeZone["utc"] as? [String] {
for utc in utcArr {
formatter.timeZone = TimeZone(identifier: utc)!
//print(utc)
for i in 1...31 {
if formatter.date(from: "2017 03 \(i)") == nil {
print("problematic time zone = \(utc) on march \(i)")
formatter.timeZone = TimeZone(identifier: "UTC")!
if let date = formatter.date(from: "2017 03 \(i)") {
print("same date with UTC = \(date)")
}
}
}
}
}
}
}
} catch {
// contents could not be loaded
}
} else {
// the URL was bad!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment