From d27121d1e9edeff5cd47024c1d8a66ce5b5ecba2 Mon Sep 17 00:00:00 2001 From: Farnabaz Date: Wed, 5 Nov 2025 09:59:29 +0100 Subject: [PATCH] fix(diff): compare date values with timestamp --- src/app/src/utils/object.ts | 10 +++++++++- src/app/test/unit/utils/database.test.ts | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/app/src/utils/object.ts b/src/app/src/utils/object.ts index d5c5c9be..8232da4c 100644 --- a/src/app/src/utils/object.ts +++ b/src/app/src/utils/object.ts @@ -1,3 +1,5 @@ +const dateRegex = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}\.\d{3}Z)?$/ + export const omit = (obj: Record, keys: string | string[]) => { return Object.fromEntries(Object.entries(obj) .filter(([key]) => !keys.includes(key))) @@ -9,7 +11,13 @@ export const pick = (obj: Record, keys: string | string[]) => { } export function isDeepEqual(obj1: Record, obj2: Record) { - if (typeof obj1 !== 'object' || typeof obj2 !== 'object') return obj1 === obj2 + if (typeof obj1 === 'string' && typeof obj2 === 'string') { + if (String(obj1).match(dateRegex) && String(obj2).match(dateRegex)) { + return new Date(obj1).getTime() === new Date(obj2).getTime() + } + return String(obj1).trim() === String(obj2).trim() + } + if (typeof obj1 !== 'object' || typeof obj2 !== 'object') return String(obj1) === String(obj2) const keys1 = Object.keys(obj1).filter(k => obj1[k] != null) const keys2 = Object.keys(obj2).filter(k => obj2[k] != null) diff --git a/src/app/test/unit/utils/database.test.ts b/src/app/test/unit/utils/database.test.ts index ad7b081a..a77aabc6 100644 --- a/src/app/test/unit/utils/database.test.ts +++ b/src/app/test/unit/utils/database.test.ts @@ -169,4 +169,21 @@ describe('isEqual', () => { expect(isEqual(document1, document2)).toBe(false) }) + + it('should return true if date values are same but different format', () => { + const document1: DatabasePageItem = { + id: 'content:index.yml', + path: '/index', + title: 'Test Document', + date: '2025-11-04', + } + const document2: DatabasePageItem = { + id: 'content:index.yml', + path: '/index', + title: 'Test Document', + date: '2025-11-04T00:00:00.000Z', + } + + expect(isEqual(document1, document2)).toBe(true) + }) })