CodableFirebase icon indicating copy to clipboard operation
CodableFirebase copied to clipboard

Setup Decoder to decode (FIR)Timestamp to (NS)Date

Open benrudhart opened this issue 7 years ago • 10 comments

Now that Firestore warns us to/ forces the usage of Timestamps over Dates I'm looking for a way to workaround this. Background: I'm using Models on iOS and watchOS as well. Firebase is not ready for watchOS hence I cannot use Timestamp in the models. Besides this I'd prefer to avoid the Firestore dependency in my models. The precision of Date is more than enough for me. My models are also contained in a framework that is not aware of Firebase, hence I cannot implement/ override the decoder that parses the Timestamps into Dates.

Question: Is there a way to setup the FirestoreDecoder to automatically parse Timestamps to Dates when a Date is expected in a model?

benrudhart avatar May 21 '18 12:05 benrudhart

Would really love a solution for this as well! I'm personally not very fond of timestamps. It's essentally rendering CodableFirebase obsolete for a lot of people until we crack it. It's breaking my models apart

kristofersdundurs avatar Jun 09 '18 16:06 kristofersdundurs

Did anyone fix this problem ?

ArEnSc avatar Jul 08 '18 18:07 ArEnSc

Seconding this sentiment. Any progress here?

andreasmpet avatar Nov 27 '18 10:11 andreasmpet

Still no fix?

ghost avatar Dec 24 '18 17:12 ghost

It'd be great to see such mapping in this library. Exposing Firebase Timestamp type to models is something all developers should stay away of.

agordeev avatar Jan 21 '19 11:01 agordeev

Can we get this fixed? It is now breaking everything

jimijon avatar Feb 18 '19 23:02 jimijon

+1.

Updated to the latest Firestore for their new groupCollection query method, but now it gives me this error when I run the app.

Swift.DecodingError.typeMismatch(Foundation.Date, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "createdAt", intValue: nil)], debugDescription: "Expected to decode Date but found FIRTimestamp instead.", underlyingError: nil))

siyao1030 avatar May 20 '19 02:05 siyao1030

+1

nikitaame avatar Nov 10 '19 22:11 nikitaame

1+

nikolausWest avatar Jan 26 '20 14:01 nikolausWest

Hi guys.

I fixed that issue.

Here you can find solution: https://github.com/mshershnev/CodableFirebase Code example is here: https://github.com/alickbass/CodableFirebase/pull/86#issuecomment-584675760

I did pull request and hope that it will be merged soon: https://github.com/alickbass/CodableFirebase/pull/86

mshershnev avatar Feb 11 '20 15:02 mshershnev