Skip to main content

Timestamps

There are two types of timestamps we use when writing data in the Collaboration system:

  • Current timestamps - these are timestamps that represent the "current time". These timestamps are used for properties such as createdAt, updatedAt, etc.
  • Past timestamps - these timestamps represent dates and times in the past.

Current timestamps#

By default, current timestamps are set to CURRENT_TIMESTAMP, which is a constant value that sets that column equal to the current time in most SQL databases.

This is configurable by passing a getNow function to the Collab Server constructor.

The getNow function accepts no parameters and must return a representation of 'now' for your database. By default, we use the value CURRENT_TIMESTAMP.

Whatever value is returned from this function will be passed into your resolvers for any current timestamps.

The following entity properties are always set to the current time:

  • createdAt
  • updatedAt
  • lastRead

Examples#

PostgreSQL NOW():

import CollabServer from '@pdftron/collab-server';
const server = new CollabServer({
getNow: () => 'NOW()',
resolvers: {
Mutation: {
addAnnotation: async (annotation) => {
console.log(annotation.createdAt) // 'NOW()'
console.log(annotation.updatedAt) // 'NOW()'
},
},
},
});

Firebase server timestamp:

import CollabServer from '@pdftron/collab-server';
import firebase from "firebase/app";
const server = new CollabServer({
getNow: () => firebase.database.ServerValue.TIMESTAMP,
resolvers: {
Mutation: {
addAnnotation: async (annotation) => {
console.log(annotation.createdAt) // {.sv: "timestamp"}
console.log(annotation.updatedAt) // {.sv: "timestamp"}
},
},
},
});

Past timestamps#

All timestamps with a known value (in the past) will be passed as a unix timestamp in MS.

In these scenarios, you will need to transform this timestamp into your databases format.

Right now, there is only one scenario where this use case happens: