Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Foundation
- func deserializeWCFDateString(json:AnyObject?) -> NSDate? {
- if let jsonDateString = json as? String {
- if countElements(jsonDateString) < 18 {
- return nil
- }
- let start = advance(jsonDateString.startIndex, 6)
- let end = advance(jsonDateString.startIndex, 18)
- let text = jsonDateString.substringWithRange(start...end)
- let msSince1970 = (text as NSString).doubleValue
- let secSince1970:NSTimeInterval = msSince1970 / 1000
- return NSDate(timeIntervalSince1970: secSince1970)
- }
- return nil
- }
- deserializeWCFDateString("/Date(1424684197910)/")
- deserializeWCFDateString("")
- deserializeWCFDateString(nil)
- deserializeWCFDateString(NSNull())
- deserializeWCFDateString("a bunch of garbage that is long enough")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement