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.

[FireStore] How to decode Timestamp in Multiplatform Code (Android/iOS)

See original GitHub issue

Given

data class Article(
    val title: String = "",
    val subTitle: String = "",
    val image: String = "",
    val date: Double = 0.0,
    val content: String = ""
)

Firebase.firestore.collection("articles")
            .get()
            .documents
            .map { doc ->
                Article(
                    doc.get("title"),
                    doc.get("subTitle"),
                    doc.get("image"),
                    doc.get("date"),
                    doc.get("content")
                )
            }

When

date is type timestamp in Firestore.

Then

How do we decode this type in commonMain for example? I have tried setting Article.date to String and Double and both crash.

 kotlinx.serialization.SerializationException: Expected Timestamp(seconds=1606944088, nanoseconds=0) to be double

Does the SDK provide any method to help with decoding this automatically?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
RZahrcommented, May 11, 2022

What about encoding it ? i.e. adding a date in the where clause Query.where(“updatedDate”, greaterThan = what_to_place_here)

0reactions
matanmarcianocommented, Dec 29, 2020

@wezley98 any solution?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I convert a Firestore date/Timestamp to Date in Kotlin?
I'm using this code: val timestamp = it["time"] as com.google.firebase.Timestamp val milliseconds = timestamp.seconds * 1000 + ...
Read more >
Get to know Firebase for Flutter - Google
How to authenticate users with Firebase Authentication and sync data with Firestore. What you'll need.
Read more >
Firebase Kotlin SDK
The official Firebase SDKs use different platform-specific ways to support writing data with and without custom classes in Cloud Firestore, Realtime Database ...
Read more >
Firebase Realtime Database and Login Tutorial (2022 Update)
It includes ready-made cross-platform code to interact with the Google ... download the Felgo Live app from the app store: Android / iOS....
Read more >
Google Codelabs
Google Developers Codelabs provide a guided, tutorial, hands-on coding experience. Most codelabs will step you through the process of building a small ...
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