feathersjs-ecosystem / feathers-sync

Synchronize service events between Feathers application instances
MIT License
221 stars 41 forks source link

Syncing events with Date value #128

Closed deskoh closed 4 years ago

deskoh commented 4 years ago

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)))
daffl commented 4 years ago

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

daffl commented 4 years ago

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