theJuls
theJuls

Reputation: 7450

FirebaseError: Timestamp out of range

I need to filter some items from a collection by date. Prior to doing the call, I am converting a date object to firebase's Timestamp, which should be doable according to the docs.

However, when I do try to do so, regardless of the date I pass in, I get the following error:

FirebaseError: Timestamp seconds out of range: Tue Sep 03 2019 17:25:38 GMT-0400 (Eastern Daylight Time)

Here is an example code of how this happens:

import * as firebase from 'firebase/app'
import * as firebaseui from 'firebaseui'
import 'firebase/auth'
import 'firebase/firestore'
import 'firebase/functions'
import 'firebase/storage'

const now = new Date()
console.log(firebase.firestore.Timestamp(now))

I have included my imports in case this somehow matters.

Anyway, did I miss something? Is there something wrong?

Upvotes: 2

Views: 2567

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317342

You're linking to Android docs, but writing in JavaScript. They aren't the same.

Use the static method fromDate() instead, which works for me using 6.5.0:

console.log(firebase.firestore.Timestamp.fromDate(new Date()))

https://firebase.google.com/docs/reference/js/firebase.firestore.Timestamp

Upvotes: 4

Related Questions