trivago / Heimdallr.swift

Easy to use OAuth 2 library for iOS, written in Swift.
Apache License 2.0
639 stars 86 forks source link

expiresAt value: timeInterval.flatMap(toNSDate) vs NSDate(timeInterval) #99

Open rauldeonate opened 7 years ago

rauldeonate commented 7 years ago

I have a problem reading "expires_in" values from OAuthAccessToken jsons. The value comes as a Unix Epoch int from the service.

The code line at OAuthAccessToken.swift let expiresAt = (json["expires_in"] as? NSTimeInterval).flatMap(toNSDate) If json["expires_in"] = 1475233174 Sets expiresAt value to: 2063-06-30 20:59:08 +0000 (this NSdate converted to UNIX epoch is 1475233174*2)

But if I change the converter to let expiresAt = NSDate(timeIntervalSince1970: (json["expires_in"] as? NSTimeInterval)!) The expiresAt value is correct

What is the difference between .flatMap and NSDate() converters? Should the json["expires_in"] be in another format?

Thanks