Handling timestamps
By default, the collaboration system uses Unix timestamps (in ms) internally.
However, this date format will not fit in with every database, and therefore timestamps need to be transformed into the correct format.
#
Transforming timestampsThere are two moments where timestamps need to be transformed - reading from a database and writing to the database.
When writing to your database, we need to convert to {your format} from Unix.
When reading from your database, we need to convert from {your format} to Unix.
#
Writing timestamps#
Writing the current timestampTimestamps such as 'createdAt', 'updatedAt', etc (current time) are set to whatever is passed into the CollabServer's getNow
option. By default, this function returns CURRENT_TIMESTAMP
which works with most SQL databases.
See the server timestamp guide for more information.
#
Writing past timestampsTo transform timestamps in the past, you can provide a getDatabaseTimestamp
option. This function accepts a unix timestamp and must return a timestamp in your desired format.
note
This function is only used to transform a known value to your required format. For setting current timestamps, see current timestamps
#
Reading timestampsThe Collab server uses Unix timestamps internally, meaning that your database's timestamps must be converted into this format.
To convert these timestamps, you can provide a parseToUnixTimestamp
option. This function accepts the timestamp from your database, and must return a unix timestamp in MS.
We will try to convert timestamps as best as possible, but in many cases you will have to provide this function.