Skip to content

Commit 35e854f

Browse files
author
Joshua Chudy
committed
update code to not assume format and use isSame from moment
1 parent d16a59a commit 35e854f

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

js/reference.js

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,29 +1673,26 @@
16731673
// don't add a column name in if it's already there
16741674
// this can be the case for multi-edit
16751675
// and if the data is unchanged, no need to add the column name to the projections list
1676-
// NOTE: This doesn't properly verify if date/timestamp/timestamptz values were changed
1677-
if (columnProjections.indexOf(colName) === -1) {
1678-
var typename = colType.rootName;
1679-
var compareWithMoment = typename === 'date' || typename === 'timestamp' || typename === 'timestamptz';
1680-
if (compareWithMoment) {
1681-
var moment = module._moment;
1682-
var formats = module._dataFormats;
1683-
1684-
// default to DATE format, if timestamp or timestamptz, change the format used
1685-
var formatToUse = formats.DATE;
1686-
if (typename === 'timestamp') {
1687-
formatToUse = formats.TIMESTAMP;
1688-
} else if (typename === 'timestamptz') {
1689-
formatToUse = formats.DATETIME.return;
1690-
}
1691-
1692-
var oldVal = moment(oldData[colName], formatToUse, true).format(formatToUse);
1693-
var newVal = moment(newData[colName], formatToUse, true).format(formatToUse);
1694-
1695-
if (oldVal != newVal) columnProjections.push(colName);
1696-
} else if ( (oldData[colName] != newData[colName]) ) {
1676+
if (columnProjections.indexOf(colName) !== -1) return;
1677+
1678+
var oldVal = oldData[colName]
1679+
var newVal = newData[colName]
1680+
1681+
var typename = colType.rootName;
1682+
var compareWithMoment = typename === 'date' || typename === 'timestamp' || typename === 'timestamptz';
1683+
// test with moment if datetime column type and one of the 2 values are defined
1684+
// NOTE: moment will test 2 null values as different even though they are both null
1685+
if (compareWithMoment && (oldVal || newVal)) {
1686+
var moment = module._moment;
1687+
1688+
var oldMoment = moment(oldData[colName])
1689+
var newMoment = moment(newData[colName])
1690+
1691+
if (!oldMoment.isSame(newMoment)) {
16971692
columnProjections.push(colName);
16981693
}
1694+
} else if (oldData[colName] != newData[colName]) {
1695+
columnProjections.push(colName);
16991696
}
17001697
};
17011698

js/utils/constants.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,10 @@
103103
DEFAULT: '*',
104104
ROWNAME: 'row_name'
105105
});
106-
106+
107107
module._dataFormats = Object.freeze({
108108
DATE: "YYYY-MM-DD",
109109
TIME: "HH:mm:ss",
110-
TIMESTAMP: 'YYYY-MM-DDTHH:mm:ss',
111110
DATETIME: {
112111
display: "YYYY-MM-DD HH:mm:ss",
113112
return: "YYYY-MM-DDTHH:mm:ssZ", // the format that the database returns when there are no fractional seconds to show

0 commit comments

Comments
 (0)