JS Dates and Callable Functions

ISO strings are the better choice

When interacting with Callable Functions, it's best to represent dates as ISO strings. It is simple to reason about: the value and the type stay consistent on the client and on the server.

If we were to work with Date fields or even Firestore Timestamps fields, the value and the type are not consistent when both sending to the server and when receiving from the server. As such, it is a discouraged pattern.

In this article, we explain what happens if we send Date and Timestamp objects to Callable Functions or if we send them to the client from Callable functions. Before being sent, both are serialized to JSON.

sending to Callable Functions

Timestamp is a Firestore specific type and doesn't get a special treatment: it serializes to an object with seconds and nanoseconds (through toJSON()).

timestamp: { seconds: 1696751687, nanoseconds: 527000000 },

As for fields of type Date, they serialize to an ISO string (through toJSON()):

date: "2023-10-08T07:54:47.527Z"

We could technically instantiate a Timestamp or a Date:

new Timestamp(timestamp.seconds, timestamp.nanoseconds)
new Date(date)

sending from Callable functions

If we attempt to return a Date object, it serializes to an ISO string.

If we attempt to return a Timestamp object, it serializes to the internal representation, possible an object with _seconds and _nanoseconds. We should avoid this pattern.

earlymorning logo

© Antoine Weber 2026 - All rights reserved

JS Dates and Callable Functions

ISO strings are the better choice

When interacting with Callable Functions, it's best to represent dates as ISO strings. It is simple to reason about: the value and the type stay consistent on the client and on the server.

If we were to work with Date fields or even Firestore Timestamps fields, the value and the type are not consistent when both sending to the server and when receiving from the server. As such, it is a discouraged pattern.

In this article, we explain what happens if we send Date and Timestamp objects to Callable Functions or if we send them to the client from Callable functions. Before being sent, both are serialized to JSON.

sending to Callable Functions

Timestamp is a Firestore specific type and doesn't get a special treatment: it serializes to an object with seconds and nanoseconds (through toJSON()).

timestamp: { seconds: 1696751687, nanoseconds: 527000000 },

As for fields of type Date, they serialize to an ISO string (through toJSON()):

date: "2023-10-08T07:54:47.527Z"

We could technically instantiate a Timestamp or a Date:

new Timestamp(timestamp.seconds, timestamp.nanoseconds)
new Date(date)

sending from Callable functions

If we attempt to return a Date object, it serializes to an ISO string.

If we attempt to return a Timestamp object, it serializes to the internal representation, possible an object with _seconds and _nanoseconds. We should avoid this pattern.