question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support Firestore Timestamps for all platforms

See original GitHub issue
Library Class Member Platforms
Firestore (iOS)
com.google.firebase (Android)
FIRTimestamp (iOS)
Timestamp (Android)
N/A All platforms

There doesn’t seem a way to reliably deserialise FIRTimestamp or com.google.firebase.Timestamp. Given this simple stub:

        val o1 = NSMutableDictionary()
        o1.setObject( FIRTimestamp(1, 2), forKey = "test" as NSString)

        val o2 = decode(TestData.serializer(), o1)

        print("@@@ $o2")

I’ve attempted to deserialise it with the decode function in dev.gitlive:firebase-common:

  1. Decode as string

    @Serializable
    data class TestData(val test: String)
    
  2. Decode as data class

    @Serializable
    data class TestData(val test: TestTimestamp)
    
    @Serializable
    data class TestTimestamp(val seconds: Long, val nanoseconds: Int)
    

(1) works, but the resulting String is coming from -[NSObject description], which is not guaranteed to be a stable string representation. The format might also differ on different platforms.

(2) does not work, since it crashes when attempting to cast the ObjC FIRTimestamp object to a Map<*, *>.

Presumably this is the cause: https://github.com/GitLiveApp/firebase-kotlin-sdk/blob/master/firebase-common/src/iosMain/kotlin/dev/gitlive/firebase/_decoders.kt#L14

Given that

  1. (AFAIK) FIRTimestamp (or its Android equivalent) is the only exception
  2. how the decoder contract of kotlinx.serialization is designed

So it seems it is a reasonable option to ad a special path for FIRTimestamp in the said code path, so as to enable (2).

I’d love to contribute on this, so please let me know if this makes sense.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
CoreyKaylorcommented, Sep 19, 2020

Probably should consider the kotlinx-datetime lib too.

1reaction
litclimbingcommented, Nov 20, 2021

I now have a working version tested on Android only so far https://github.com/litclimbing/firebase-kotlin-sdk/tree/add-timestamp

My approach was to create specialized encoder/decoders and provide dummy serializers for the special types. The encoder/decoder look for the special types in the encode/decodeSerializableValue functions and does the translation there.

I also removed all the positive infinity double stuff used as a flag for the server timestamps. The FieldValues are recognized by the encoder and passed through.

Currently, I’ve only added support for firestore. The database module will need its own support added.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Timestamp | JavaScript SDK | Firebase JavaScript API reference
Reference for Timestamp. ... Explore all solutions ... Manage Firebase projects · Supported platforms & frameworks · Use Emulator Suite.
Read more >
Update a Firestore document Timestamp - Google Cloud
Update a Firestore document Timestamp. ... Update a Firestore document Timestamp. bookmark_border. Stay organized with collections Save and categorize ...
Read more >
Add timestamp in Firestore documents - firebase
Important: Unlike "push IDs" in the Firebase Realtime Database, Cloud Firestore auto-generated IDs do not provide any automatic ordering. If you ...
Read more >
The secrets of Firestore's FieldValue.serverTimestamp()
Everything you need to know about Firestore server timestamps, ... There are a few different types of FieldValue s, and they all act...
Read more >
How to use the @google-cloud/firestore.Timestamp.fromDate ...
To help you get started, we've selected a few @google-cloud/firestore.Timestamp. ... return Promise.all(p).then(() => { return new Promise((resolve, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found