Created
February 27, 2017 18:32
-
-
Save romaHerman/f119885591250a2dc5f0ebed8ac4b37f to your computer and use it in GitHub Desktop.
This file contains 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
//: 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