Modify update to compare dates/timestamps better #1006
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses an issue in chaise where a timestamptz value can be submitted to ermrest for update but the value was unchanged. This can occur if the old/new value has fractional seconds and the other value doesn't. This can also occur when the timezone of the user is different from the timezone the data is returned in.
For the case of date and timestamp, it's almost unlikely that this precision matters but it's still worth converting these values to similar formats anyways to ensure a consistent comparison.
using
isSame()
from momentFor comparing dates and timestamps, instead of defining the format and outputting the moment object using
.format()
, I’m letting moment parse the value without telling it the format. To compare the values, usingisSame()
works how we expect when the values can be properly parsed to moment objects.On thing to note, f the values are both null, moment will create an object with “invalid date” as the value for both. When you use
isSame()
for 2 invalid dates that both were created from null, they are considered different.Related ermrestJS issue #463