The behavior for Date objects stored in Firestore is going to change AND YOUR APP MAY BREAK

in #utopian-io6 years ago (edited)

featured.png

<p dir="auto">That's a catchy title to grab your attention. But you don't need to worry no more. The Firebase SDK already allows you to configure the behavior properly on all officially supported platforms. And with this pull request merged, you can now also configure Flutter properly to avoid problems. <h2>Repository <p dir="auto"><span><a href="https://github.com/flutter/plugins" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">https://github.com/flutter/plugins <h2>New Features <p dir="auto"><span>Pull request: <a href="https://github.com/flutter/plugins/pull/765" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">https://github.com/flutter/plugins/pull/765 <p dir="auto">Adding complete support for all Firestore settings. The need originated from the upcoming change of snapshot timestamps that are announced if <code>timestampsInSnapshotsEnabled isn't set to <code>true. <p dir="auto">Firebase has already announced the change of datatype for the Firestore timestamp, which will likely be a source of error if not configured properly for applications that are using Cloud Firestore. <p dir="auto">This is fixing the warnings that are announced when using the Cloud Firestore without the proper settings. As displayed below. <pre><code>W/Firestore( 9705): (0.6.6-dev) [Firestore]: The behavior for java.util.Date objects stored in Firestore is going to change AND YOUR APP MAY BREAK. W/Firestore( 9705): To hide this warning and ensure your app does not break, you need to add the following code to your app before calling any other Cloud Firestore methods: W/Firestore( 9705): W/Firestore( 9705): FirebaseFirestore firestore = FirebaseFirestore.getInstance(); W/Firestore( 9705): FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder() W/Firestore( 9705): .setTimestampsInSnapshotsEnabled(true) W/Firestore( 9705): .build(); W/Firestore( 9705): firestore.setFirestoreSettings(settings); W/Firestore( 9705): W/Firestore( 9705): With this change, timestamps stored in Cloud Firestore will be read back as com.google.firebase.Timestamp objects instead of as system java.util.Date objects. So you will also need to update code expecting a java.util.Date to instead expect a Timestamp. For example: W/Firestore( 9705): W/Firestore( 9705): // Old: W/Firestore( 9705): java.util.Date date = snapshot.getDate("created_at"); W/Firestore( 9705): // New: W/Firestore( 9705): Timestamp timestamp = snapshot.getTimestamp("created_at"); W/Firestore( 9705): java.util.Date date = timestamp.toDate(); W/Firestore( 9705): W/Firestore( 9705): Please audit all existing usages of java.util.Date when you enable the new behavior. In a future release, the behavior will be changed to the new behavior, so if you do not follow these steps, YOUR APP MAY BREAK. <p dir="auto"><br /><br /> The <a href="https://firebase.google.com/docs/reference/js/firebase.firestore.Timestamp" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">Firestore timestamps will provide a with a much higher accuracy of time, down to nanoseconds since the regular date objects with millisecond precision causes a truncation that can lead to problems in subsequent queries where the nano-second accuracy differs. <h2>GitHub Account <p dir="auto"><span><a href="https://github.com/DennisAlund" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">https://github.com/DennisAlund
Sort:  

Hi there,

That's a great contribution on a well-known project. Hope to see you around more. :)


Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.



Chat with us on Discord.
[utopian-moderator]Need help? Write a ticket on https://support.utopian.io/.

Thank you for your review, @emrebeyler!

So far this week you've reviewed 3 contributions. Keep up the good work!

Can I have a question?
I found this tag utopian-io by chance.
What is this tag's main topic? How can I enjoy this tag's post?
I just wonder about it and looked your post..

Hi @dennisalund!



Feel free to join our @steem-ua Discord serverYour post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation! Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!

Hey, @dennisalund!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
SteemPlus or Steeditor). Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Congratulations @dennisalund! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

<table><tr><td><span><img src="https://images.hive.blog/768x0/https://steemitimages.com/60x70/http://steemitboard.com/@dennisalund/payout.png?201811030045" srcset="https://images.hive.blog/768x0/https://steemitimages.com/60x70/http://steemitboard.com/@dennisalund/payout.png?201811030045 1x, https://images.hive.blog/1536x0/https://steemitimages.com/60x70/http://steemitboard.com/@dennisalund/payout.png?201811030045 2x" /><td>You received more than 100 as payout for your posts. Your next target is to reach a total payout of 250 <p dir="auto"><sub><em><a href="https://steemitboard.com/@dennisalund" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">Click here to view your Board of Honor<br /> <sub><em>If you no longer want to receive notifications, reply to this comment with the word <code>STOP <p dir="auto"><strong><span>Do not miss the last post from <a href="/@steemitboard">@steemitboard: <table><tr><td><a href="https://steemit.com/steemfest/@steemitboard/i06trehc" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link"><img src="https://images.hive.blog/768x0/https://steemitimages.com/64x128/https://ipfs.io/ipfs/QmU34ZrY632FFKQ1vbrkSM27VcnsjQdtXPynfMrpxDFJcF" srcset="https://images.hive.blog/768x0/https://steemitimages.com/64x128/https://ipfs.io/ipfs/QmU34ZrY632FFKQ1vbrkSM27VcnsjQdtXPynfMrpxDFJcF 1x, https://images.hive.blog/1536x0/https://steemitimages.com/64x128/https://ipfs.io/ipfs/QmU34ZrY632FFKQ1vbrkSM27VcnsjQdtXPynfMrpxDFJcF 2x" /><td><a href="https://steemit.com/steemfest/@steemitboard/i06trehc" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">Be ready for the next contest! <blockquote> <p dir="auto">Support <a href="https://steemit.com/@steemitboard" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">SteemitBoard's project! <strong><a href="https://v2.steemconnect.com/sign/account-witness-vote?witness=steemitboard&approve=1" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">Vote for its witness and <strong>get one more award!

Congratulations @dennisalund! You received a personal award!

1 Year on Steemit

Click here to view your Board of Honor

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @dennisalund! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!