Giter VIP home page Giter VIP logo

Comments (11)

LaughDonor avatar LaughDonor commented on July 26, 2024

Excellent find! I verified the issue, and saw that GAS doesn't like the extra precision that Firebase gives.

from firestoregoogleappsscript.

grahamearley avatar grahamearley commented on July 26, 2024

Thanks for reporting this!

I'm trying to recreate the issue and not having any luck in v19. Could one of you add some code for how to recreate this? Here's my test:

function saveAndReadDates() {
  const now = Date()
  
  const dateObj = {
    "date" : now
  }
  
  firestore.createDocument("DateTests/madeInScript", dateObj)
  
  // Read the value we created in this script, and one
  //  that I created in the Firestore console.
  const madeInScript = firestore.getDocument("DateTests/madeInScript");
  const madeInFirestore = firestore.getDocument("DateTests/madeInFirestore");
  
  Logger.log("Document made in script:");
  Logger.log(madeInScript)
  
  Logger.log("Document made in firestore:");
  Logger.log(madeInFirestore);
  
  const scriptDate = madeInScript.fields.date;
  const firestoreDate = madeInFirestore.fields.date;
  
  Logger.log("Script doc's date: " + scriptDate);
  Logger.log("Firestore doc's date: " + firestoreDate);
}

And here are the logs that get printed:

[18-07-14 09:39:32:592 CDT] Document made in script:
[18-07-14 09:39:32:593 CDT] {createTime=2018-07-14T14:39:32.489421Z, name=projects/xxxxxx/databases/(default)/documents/DateTests/madeInScript, updateTime=2018-07-14T14:39:32.489421Z, fields={date=Sat Jul 14 2018 09:39:32 GMT-0500 (CDT)}}
[18-07-14 09:39:32:593 CDT] Document made in firestore:
[18-07-14 09:39:32:594 CDT] {createTime=2018-07-14T14:36:27.721690Z, name=projects/xxxxxx/databases/(default)/documents/DateTests/madeInFirestore, updateTime=2018-07-14T14:36:27.721690Z, fields={date=Sat Jul 14 14:08:38 GMT-05:00 2018}}
[18-07-14 09:39:32:594 CDT] Script doc's date: Sat Jul 14 2018 09:39:32 GMT-0500 (CDT)
[18-07-14 09:39:32:595 CDT] Firestore doc's date: Sat Jul 14 2018 14:08:38 GMT-0500 (CDT)

from firestoregoogleappsscript.

LaughDonor avatar LaughDonor commented on July 26, 2024

I recreated the issue by passing the date string to new Date ().

function tester() {
  var x = new Date("2014-10-02T15:01:23.045123456Z")
  var y = 0
}

And putting a breakpoint on the second line.

And just now I'm realizing that my fix needs a bit more work cause it doesn't get the substring from the end of the format if there are other precision levels.

from firestoregoogleappsscript.

grahamearley avatar grahamearley commented on July 26, 2024

@LaughDonor Where did you get that Date string? Doesn't the timestamp type get parsed into a Date object when read from Firestore here?

When does this error occur when interacting with the library?

from firestoregoogleappsscript.

LaughDonor avatar LaughDonor commented on July 26, 2024

I clicked on the link OP posted. And that is exactly where the issue lies.

The issue would happen whenever they grab a document with a datetime in that RFC format.

from firestoregoogleappsscript.

grahamearley avatar grahamearley commented on July 26, 2024

Okay, I see that there's an issue parsing Dates formatted that way in Google Apps Scripts. But when I add documents with timestamp fields and read them back from Firestore using the library, I see the correct date coming in. Do you have a test case for reading timestamp fields from a Firestore document where the date comes in incorrectly?

I think I'm missing something here about how to reproduce this.

from firestoregoogleappsscript.

LaughDonor avatar LaughDonor commented on July 26, 2024

I didn't take the time to do this.. but it should theoretically be possible with an existing Database.

from firestoregoogleappsscript.

grahamearley avatar grahamearley commented on July 26, 2024

Yeah, that's what I'm thinking too but I'm not seeing the issue 😕. Thanks for helping me see what's going on though!

@marchovarela Could you add some code for reproducing this bug? I see how it should be happening, but I'm not able to reproduce it and just want to fully verify this before we make a change.

from firestoregoogleappsscript.

LaughDonor avatar LaughDonor commented on July 26, 2024

@grahamearley, I've updated my PR. This will cover all those edge cases that may have that value saved, if it exists.

from firestoregoogleappsscript.

LaughDonor avatar LaughDonor commented on July 26, 2024

Gah, I took another crack at reading the Firestore Docs - Value storage and I read that it stores the data and removes that extra precision internally anyway. Since that format coincides with the format which GaS parses the date string; there doesn't seem to be an issue, and I recommend this should be closed unless @marchovarela can produce an example to the contrary.

from firestoregoogleappsscript.

grahamearley avatar grahamearley commented on July 26, 2024

Okay great! Thanks for jumping on this issue @LaughDonor.

I'll close this for now. @marchovarela -- reply if we're missing something and should reopen.

from firestoregoogleappsscript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.