Comments (11)
Excellent find! I verified the issue, and saw that GAS doesn't like the extra precision that Firebase gives.
from firestoregoogleappsscript.
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.
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.
@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.
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.
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.
I didn't take the time to do this.. but it should theoretically be possible with an existing Database.
from firestoregoogleappsscript.
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.
@grahamearley, I've updated my PR. This will cover all those edge cases that may have that value saved, if it exists.
from firestoregoogleappsscript.
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.
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)
- Key error on query HOT 10
- Remove specific fields using `updateDocuments` - feature request/question HOT 26
- What is the best way to protect the private key in a container bound script
- Is there anyway to update a nested field but leave other fields unchanged? HOT 1
- Unable to update nested fields with custome mask in updateDocument()
- getDocuments has SyntaxError: Unexpected end of JSON input HOT 3
- Apps script FirestoreApp when query 'collection1' where 'timestampField' == my_variable_Timestamp HOT 1
- Use the count() aggregation
- Queries using != and not-in
- Inserting Weird Values After Updating
- getDocuments() doesn't return the path of each document HOT 1
- Firestore feature missing HOT 1
- Prevent auto conversion to GeoPoint HOT 1
- How do I create a query which compares a value which is inside a map in the document? HOT 1
- README Properties Service key retrieval error HOT 4
- Subcollection being created upon updating Firestore collection HOT 2
- FieldValue support HOT 7
- FieldTransform Support
- "Bad Request" Issue when updating / querying document information HOT 2
- Poor performance when updating thousands of data HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from firestoregoogleappsscript.