feathersjs-ecosystem / feathers-sync

Synchronize service events between Feathers application instances

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Syncing events with Date value

deskoh opened this issue · comments

Events are currently serialized using JSON.stringify. Since Date values are not supported in JSON (see here), it will be converted to string. When received, the value will be converted to a string when serialized. This will be 'lossy', in particular, milliseconds accuracy is lost.

const date = { date: new Date() }

// {date: Mon Oct 21 2019 21:41:56 GMT+0800 (Singapore Standard Time)}
console.log(date)

// {date: "2019-10-21T13:41:56.915Z"}
console.log(JSON.parse(JSON.stringify(date)))

I'm wondering if there should be a way to provide a custom serializer/deserializer. There is probably other cases where you want to convert things. This would also take care of #87

This can now be done in v1.2.0 and later by using a custom serializer/deserializer.