-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
createPatch does not support Date type #100
Comments
Getting the same issue. @chbrown is this possible to be verified or that I can help in to resolve the issue? |
RFC 6902 Section 3 says
JavaScript's There is the "optional diff argument" (search the README) which lets you pick which of those outcomes you want. Maybe there should be a batteries-included module of diff functions that users could import and plug into that argument, to avoid having to write their own. |
@chbrown good point on the use of the optional diff argument. Although it does seem like since If the user so wishes a Of course this has the side effect that if you stringify and parse the patch you will not be able to apply the patch correctly since its not a reversible action. Maybe we transform the Date into SuperClass of Date which has a custom toJSON method resulting in a transformation like: class PatchableDate extends Date {
toJSON() {
return {"@type": "ISODate", "value": this.toISOString()}
}
}
const a = new PatchableDate("2024-11-28T10:09:08.000Z")
console.log(JSON.stringify(a) === `{"@type":"date","value":"2024-11-28T10:09:08.000Z"}`) This would allow people to keep using whatever logic they want on a JS Date object. At the very least we should definitely be supporting the comparison case of Dates. const dateA = new Date("2024-11-28")
const dateB = new Date("2025-12-29") should result in a patch. |
Following on from #78 ,
createPatch
should have Date handling added so that JS objects with a Date object inside are handled correctly.Currently they are effectively ignored.
This is because in the current handling of diff, Date objects get read as an
object
type and so it attempts to iterate over its keys of which there are none, resulting in an empty patch despite the value being different.The text was updated successfully, but these errors were encountered: