Working with Date and Times

Pulsar uses the Salesforce API to sync data, and as a result, stores dates and times in a Salesforce API-compatible format. See the Salesforce documentation (here: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_valid_date_formats.htm) for more information on the valid date and datetime format for use with Salesforce. Specifically, this data is always stored in the ISO8601 format, and the timezone is always UTC, as denoted by the suffix 'Z' for datetimes.

Developers on the Pulsar platform can expect to retrieve and create data using these formats. As a result when creating or updating objects with date or datetime information, it is important to convert to the correct format. This can be done by parsing or building date or datetime information using the Javascript Date object, and creating a string representation using the toISOString() method (documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString).

Example:

const event = new Date('05 October 2011 14:48 GMT-0500'); // parsing a date string console.log(event.toString()); // Expected output: "Wed Oct 05 2011 15:48:00 GMT-0400 (Eastern Daylight Time)" // Note: your timezone may vary console.log(event.toISOString()); // to UTC ISO 8601 format (Salesforce datetime) // Expected output: "2011-10-05T19:48:00.000Z" console.log(event.toISOString().substr(0,10)); // convert to a Salesforce date value // Expected output: "2011-10-05"

There are several popular libraries available for the manipulation of date and datetime information which may also assist in producing the correct format.