Creating and comparing dates within CosmosDB stored procedures

There is limited guidance for CosmosDB stored procedures and their processing new Date()and date comparisons.

The following code is a CosmosDB stored procedure for freezing documents after a specified time. The property currentDoc.FreezeDateis in the format ISO-8601, for example .. '2017-11-15T13: 34: 04Z

Note: this is an example of a situation that I am trying to understand. This is not production code.

function tryUpdate(newDoc) {
  __.queryDocuments(
    __.getSelfLink(),
    { /* query to fetch the document */ },
    (error, results) => {
      var currentDoc = results[0]; // doc from the database
      // fail if the document is still locked
      if (new Date(currentDoc.FreezeDate) < new Date()) {
        getContext().getResponse().setBody({ success: false });
        return;
      }
      // else update the document
      /* snip */
    }
  );
}

My question is: inside CosmosDB stored procedures, it new Date()affects time zones, especially considering that the database may be in a different region than the calling code? Is the date comparison code valid in all situations?

+6
1

, CosmosDB DateTime Timezone, . DateTimeOffset. , , , :

  "2014-09-15T23:14:25.7251173Z"

Date Javascript - - . Date . (, , ) ( ... String).

( javascript )

, , , new Date() .

, (Unix Time). , (new Date().value - ). , _ts .

, new Date() " " - , Azure/Cosmos .

+1

All Articles