1

I'm making a calendar with react, redux, react big calendar and firebase. the problem is that the events are not displayed in the calendar. I think that this is because the format of the dates, is in seconds and nanoseconds.

Searching how to solve this i found that using toDate() and new Date() can convert the dates to javascript dates, but it didn't work.

and already read: How do I convert a Firestore date/Timestamp to a JS Date()?

but still cant figure out how to do it

i tried doing this buti get "invalid date":

events.map(event => console.log(toDate(event.start)))

i hope that someone can help me. thanks!!

github: https://github.com/guidomora/peluqueria-new-calendar.git

Code to return the events from firebase:

  const startLoadingEvents = async () => {
    const querySnapshot = await getDocs(collection(db, "tobias"));
    const events = [];
    querySnapshot.forEach((doc) => {
      events.push({id: doc.id, ...doc.data()});
    });
    dispatch(setEvent(events))
  };

Console:

console

Event in firebase:

firebase

Drew Reese
  • 165,259
  • 14
  • 153
  • 181
guido
  • 71
  • 5

1 Answers1

1

The accepted answer on the other question you cited is saying that there is a toDate method on a Timestamp object. What you tried:

toDate(event.start))

is not calling a method. That's just calling a standalone function called "toDate", and there is no such function provided by the Firestore SDK.

If you are saying that event.start is a Firestore Timestamp type object, then you can call its toDate method like this:

event.start.toDate()

to get a Date out of it. But we can't see what event.start is exactly, so I'm just guessing here.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441