Sittiphan Sittisak
Sittiphan Sittisak

Reputation: 885

Flutter & Firestore: The error will occur when data in the field type timestamp has a value before 1/1/1970 at 7 AM

It can set timestamp value before 1/1/1970 at 7 AM in firestore like this: enter image description here

But when I fetch this data in my flutter project the error will alert with this:

Error: Invalid argument(s): Timestamp nanoseconds out of range: -233000000

How to solve this? I just try to check the range of timestamp ( '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC).

It works successfully when I set the timestamp field after 2038-01-19 03:14:07 (I found the limit of year is 10,000).

Should I record DateTime with the timestamp type or I should save it in the String type? What is the field type that most people used for DateTime in firestore?

Upvotes: 0

Views: 394

Answers (1)

Jet.B.Pope
Jet.B.Pope

Reputation: 760

Personally, I would just save the dates as strings and use the DateTime.parse() method in flutter or something similar in your backend code when needing to convert it back. An exception to this would be if you need to perform queries on your Firestore docs based on these dates.

Upvotes: 1

Related Questions