From 777a8d400726644970ae231cd83fbee8bc377da0 Mon Sep 17 00:00:00 2001 From: Khaled Garbaya Date: Thu, 14 Dec 2017 11:25:50 +0100 Subject: [PATCH] fix: strip milliseconds from date --- lib/entry-state.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/entry-state.js b/lib/entry-state.js index be252e2..a3f8501 100644 --- a/lib/entry-state.js +++ b/lib/entry-state.js @@ -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 - } 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 return } }) // 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 } return entry } + +function isDateEqual (lhs, rhs) { + const lhsDate = new Date(lhs) + const rhsDate = new Date(rhs) + return lhsDate.setMilliseconds(0) === rhsDate.setMilliseconds(0) +}