I have a function that compares different models, one model is from the initial state of the form(the model comes from the backend service, which is a date object), and the other one is when it is converted in the front end.
function getPropertyDifferences(obj1, obj2) { return Object.entries(obj1).reduce((diff, [key, value]) => { // Check if the property exists in obj2. if (obj2.hasOwnProperty(key)) { const val = obj2[key]; // Check if obj1's property's value is different from obj2's. if (val !== value) { return { ...diff, [key]: val, }; } } // Otherwise, just return the previous diff object. return diff; }, {}); } const a = { dateOfBirth: "Wed Jan 06 2021 12:00:05 GMT-0700 (Mexican Pacific Standard Time)", name: "test" }; const b = { dateOfBirth: "2021-01-06T12:00:05.357", name: "test" }; console.log(getPropertyDifferences(a, b)); As you can see, the dates are the same but in different formats; how can I validate in the function that it is the same?
new Date(stringRepresentation)dateOfBirthinbis ambiguous since it doesn't have any timezone information in it, so it depends on the location of the user