Created
April 5, 2017 11:33
-
-
Save alicanbatur/40397fea54590b61ae5683c7c58f56be to your computer and use it in GitHub Desktop.
ObjectMapper date transform (formatter) for FIRServerValue.timestamp(). Firebase's timestamp.
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
import Foundation | |
import ObjectMapper | |
open class FirebaseDateTransform: TransformType { | |
public typealias Object = Date | |
public typealias JSON = Double | |
public init() {} | |
open func transformFromJSON(_ value: Any?) -> Date? { | |
if let t = value as? TimeInterval { | |
return Date(timeIntervalSince1970: t/1000) | |
} | |
return nil | |
} | |
open func transformToJSON(_ value: Date?) -> Double? { | |
if let date = value { | |
return Double(date.timeIntervalSince1970) | |
} | |
return nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is an error in the
transformToJSON
. Should be multiplied by 1000.