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 moment
For 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, using isSame() 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.
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