fix: strip milliseconds from date

This commit is contained in:
Khaled Garbaya
2017-12-14 11:25:50 +01:00
parent e3509ccc5c
commit 1d8bf9c3dd

View File

@@ -37,15 +37,21 @@ module.exports = async function attachEntryState (entry) {
} }
}) })
// If the field is a single reference we just check if it has pending changes // If the field is a single reference we just check if it has pending changes
} else if (isObject(item[0]) && (!item[0].fields || item[0].sys.updatedAt !== item[1].sys.updatedAt)) { } else if (isObject(item[0]) && (!item[0].fields || !isDateEqual(item[0].sys.updatedAt !== item[1].sys.updatedAt))) {
entry.pendingChanges = true entry.pendingChanges = true
return return
} }
}) })
// We check if the root element has pending changes // We check if the root element has pending changes
if (entry && publishedEntry && (entry.sys.updatedAt !== publishedEntry.sys.updatedAt)) { if (entry && publishedEntry && (!isDateEqual(entry.sys.updatedAt !== publishedEntry.sys.updatedAt))) {
entry.pendingChanges = true entry.pendingChanges = true
} }
return entry return entry
} }
function isDateEqual (lhs, rhs) {
const lhsDate = new Date(lhs)
const rhsDate = new Date(rhs)
return lhsDate.setMilliseconds(0) === rhsDate.setMilliseconds(0)
}