Search code examples
parse-platformparse-server

parse-server returns wrong Date format


When querying on Parse server this is the result:

{
    "results": [
        {
            "objectId": "BMRfgFD1SU",
            "username": "demo@user.com",
            "createdAt": "2017-04-13T16:52:37.661Z",
            "updatedAt": "2017-04-13T16:52:37.661Z",
            "ACL": {
                "*": {
                    "read": true
                },
                "BMRfgFD1SU": {
                    "read": true,
                    "write": true
                }
            }
        }
    ]
}

The problem is that the date format now is a String however it should be like:

{
 "__type": "Date",
 "iso": "2015-03-01T15:59:11-07:00"
}

Solution

  • The Parse date type is able to parse various different formats. parse-server itself uses a specific format, and wherever you're setting the date elsewhere is using a different format is all. If you need more consistency, add a helper function to enforce / update dates to a specific format, and call it anywhere you take a date as input to a cloud function and in the beforeSave trigger of any class that has a date type field.

    Your other option is to make sure anywhere you send / use dates from your clients format the data properly, but this is less future proof.

    Edit - I recommend in your validation / formatting you adhere to the format of created/updatedAt, as you are not able to modify those values set by Parse-Server.