parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

Issue with date fields

Open slimshdy opened this issue 10 years ago • 12 comments

Hi! When I get a date field of an object using php sdk, it usually returns a dateTime and I was able to hadle it: (e.g.)

$now = new DateTime();
$diff = $now->diff($task->get("start"));

Now, with parse-server open source version, it returns a string that must be parsed in order to handle it.

slimshdy avatar Feb 04 '16 10:02 slimshdy

Will take a look, the php sdk needs some changes anyway.

gfosco avatar Feb 04 '16 15:02 gfosco

It's not a php issue, it's a parse-server issue. Parse-server must return an array like this when the field in the mongodb collection is a ISODate field:

{"__type":"Date","iso":"2016-02-29T08:00:00.000Z"}

but it's returning a string like 2016-02-29T08:00:00.000Z

slimshdy avatar Feb 05 '16 18:02 slimshdy

only createdAt, updatedAt and expiresAt are returned like strings instead of {"__type":"Date","iso":""} why are you considering expiresAt as a special field? special fields are createdAt, updatedAt and objectId

slimshdy avatar Feb 05 '16 19:02 slimshdy

Yup, valid bug, fix is incoming next week.

nlutsenko avatar Feb 06 '16 07:02 nlutsenko

Just remove all expiresAt occurrences from transform.js in parse-server because expiresAt is not a magic field. Only magic fields are returned like strings and parsed in the sdk.

parse-server failed because I had a collection with a field named expiresAt.

slimshdy avatar Feb 06 '16 19:02 slimshdy

Not as easy, but quite close. expiresAt is a magic field, but only for _Session objects. Also, we treat sub objects wrong, as well as convert all occurrences of typed Date objects into iso dates, where only root level should be converted.

nlutsenko avatar Feb 06 '16 21:02 nlutsenko

We just hit this issue as well. Look forward to seeing the fix land.

mattmo avatar Feb 10 '16 01:02 mattmo

Please reopen if you're still experiencing this with 2.1.2. Thanks.

gfosco avatar Feb 20 '16 02:02 gfosco

Why is this thread closed? It's not fixed.

joeyslack avatar Mar 01 '16 00:03 joeyslack

Not sure, but let's reopen to confirm.

nlutsenko avatar Mar 01 '16 00:03 nlutsenko

So for reference:

In the hosted Parse.com server, the cloudcode was giving us: 2016-03-01T18:30:36.806Z. In the self-hosted parse server (most recent version: 2.1.3), it's giving: 2016-03-02 17:56:29 +0000.

Let me know if you need anything else.

joeyslack avatar Mar 01 '16 17:03 joeyslack

We made some updates to expiresAt handling in recent versions, so this should be fixed now. Please open a new issue if you encounter the same problem.

drew-gross avatar Mar 30 '16 16:03 drew-gross