Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/app/src/utils/object.ts
Original file line number Diff line number Diff line change
@@ -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<string, unknown>, keys: string | string[]) => {
return Object.fromEntries(Object.entries(obj)
.filter(([key]) => !keys.includes(key)))
Expand All @@ -9,7 +11,13 @@ export const pick = (obj: Record<string, unknown>, keys: string | string[]) => {
}

export function isDeepEqual(obj1: Record<string, unknown>, obj2: Record<string, unknown>) {
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)
Expand Down
17 changes: 17 additions & 0 deletions src/app/test/unit/utils/database.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
Loading