flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

Add `isUtc` to the `Timestamp.toDate`

Open Vorkytaka opened this issue 1 year ago • 2 comments

Description

Ability to convert Timestamp objects to the UTC DateTime object.

In case, when we save UTC timestamps to the firestore, we need to restore them in that state. Currently, we need to create DateTime someway like this:

          final Timestamp timestamp = // get timestamp object
          final datetime = DateTime.fromMicrosecondsSinceEpoch(
            timestamp.microsecondsSinceEpoch,
            isUtc: true,
          );

With this changes we will just use build-in methods.

Checklist

  • [x] I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • [x] My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • [x] All existing and new tests are passing.
  • [x] I updated/added relevant documentation (doc comments with ///).
  • [x] The analyzer (melos run analyze) does not report any problems on my PR.
  • [x] I read and followed the Flutter Style Guide.
  • [x] I signed the CLA.
  • [x] I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • [ ] Yes, this is a breaking change.
  • [x] No, this is not a breaking change.

Vorkytaka avatar Jan 22 '24 23:01 Vorkytaka

Hey @Vorkytaka, thanks for your PR. You can already convert easily using

timestamp.toDate().toUtc()

Do you think it's enough for your usecase? Thanks

Lyokone avatar Jan 23 '24 13:01 Lyokone

Hey @Vorkytaka, thanks for your PR. You can already convert easily using

timestamp.toDate().toUtc()

Do you think it's enough for your usecase? Thanks

The problem is that we create two DateTime objects. :(

Vorkytaka avatar Jan 23 '24 13:01 Vorkytaka

Discussing internally we don't think the optimisation is worth adding the API.

Lyokone avatar Mar 11 '24 13:03 Lyokone