Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

195
Views
Multiple Variations of Firebase Timestamps

I store a list of users invited to an organisation, together with the timestamp denoting when the invite expires in Firebase. When I pull the timestamp from Firebase, I parse it to determine if it's still valid or has expired using:

Client Code

const inviteStatus = invitee?.validUntil.toDate() >= Date.now() ? 'valid_invitee' : 'expired_invitee'

I have also built in functionality to generate new invites via a call to Firebase Cloud Functions. Once an invite has been created, I return a new invitee object:

Firebase Functions Code

const expiryDate = admin.firestore.Timestamp.now().toDate()
expiryDate.setTime(expiryDate.getTime() + (1000 * 60 * 60 * 24 * 7)) // 7-day expiration

return {
    invitee: {
        validUntil: admin.firestore.Timestamp.fromDate(expiryDate)
    }
}

The reason I don't return just a Date object but instead convert it to Firestore's Timestamp format is to ensure that client always receives the validUntil data in the same format, regardless of whether it's read directly from Firestore DB or returned via Firebase Cloud Functions.

However, once this invitee object is returned and the client code runs (see first code snippet), I get the following error:

Uncaught TypeError: invitee.validUntil.toDate is not a function

Investigating

I have printed both objects (one directly pulled from DB and another returned via Cloud Functions) and noticed that the object returned directly from DB, when printed, shows a ut in Chrome Dev Tools next to the validUntil object, whereas the object returned from Cloud Functions does not display ut.

Printed Object Queried from Firestore enter image description here

Printed Object Returned from Cloud Functions enter image description here

Question

Why is Firebase generating two different types of timestamp objects where one can be converted to Date using .toDate() function and another throws an error?

Is there a way to return a proper timestamp object via Cloud Functions that I will be able to apply .toDate() function on in the client?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!