Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. import Foundation
  2.  
  3. func deserializeWCFDateString(json:AnyObject?) -> NSDate? {
  4.  
  5. if let jsonDateString = json as? String {
  6.  
  7. if countElements(jsonDateString) < 18 {
  8. return nil
  9. }
  10.  
  11. let start = advance(jsonDateString.startIndex, 6)
  12. let end = advance(jsonDateString.startIndex, 18)
  13. let text = jsonDateString.substringWithRange(start...end)
  14.  
  15. let msSince1970 = (text as NSString).doubleValue
  16. let secSince1970:NSTimeInterval = msSince1970 / 1000
  17.  
  18. return NSDate(timeIntervalSince1970: secSince1970)
  19. }
  20.  
  21. return nil
  22. }
  23.  
  24. deserializeWCFDateString("/Date(1424684197910)/")
  25. deserializeWCFDateString("")
  26. deserializeWCFDateString(nil)
  27. deserializeWCFDateString(NSNull())
  28. deserializeWCFDateString("a bunch of garbage that is long enough")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement