Reputation: 428
I am trying to create a firebase firestore timestamp object by passing number of seconds to it, but it is not working.
Here's the code snippet.
import com.google.firebase.Timestamp
import com.google.firebase.firestore.*
var timeStampString:String = "1438910477"
var t = timeStampString.toLong()
var ts = Timestamp(t)
I am getting error:
None of the following functions can be called with the arguments supplied
<Init>(Parcel) defined in com.google.firebase.Timestamp
<Init>(Date) defined in com.google.firebase.Timestamp
I am passing number as the parameter as mentioned in documentation. But it is expecting "Parcel" or "Date".
What am I doing wrong?
Upvotes: 2
Views: 2298
Reputation: 317692
As you can see from the API documentation you linked to, the constructor requires two number parameters, not one. If you don't have a component in nanoseconds to pass, then pass 0:
var timeStampString:String = "1438910477"
var t = timeStampString.toLong()
var ts = Timestamp(t, 0)
But, why parse a string to a number when you can code the number directly:
var t = 1438910477
var ts = Timestamp(t, 0)
Upvotes: 4