From 7ce06803dcd20af5339cde83dc6ff82381cc9caf Mon Sep 17 00:00:00 2001 From: lorentz Date: Tue, 17 Mar 2026 23:01:18 -0400 Subject: [PATCH] fix: time entries incremental sync uses lastModifiedDateTime not dateWorked Previously the incremental filter compared dateWorked >= lastSyncTime, meaning edits to existing entries (hours adjusted, notes changed, PTO blocks entered in advance) were never picked up after initial ingestion. Switch both the lastModifiedField mapping and buildTimeEntriesFilter to use lastModifiedDateTime so any created or modified entry is captured on the next scheduled sync. --- lib/utils/sync-helpers.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/utils/sync-helpers.ts b/lib/utils/sync-helpers.ts index d259d1e..6af2ece 100644 --- a/lib/utils/sync-helpers.ts +++ b/lib/utils/sync-helpers.ts @@ -162,7 +162,7 @@ export function getLastModifiedField(entity: EntityType): string { [EntityType.CONTRACT_SERVICES]: 'lastModifiedDate', [EntityType.AUTOTASK_SERVICES]: 'lastModifiedDate', [EntityType.BILLING_ITEMS]: 'itemDate', - [EntityType.TIME_ENTRIES]: 'dateWorked', + [EntityType.TIME_ENTRIES]: 'lastModifiedDateTime', [EntityType.TICKET_NOTES]: 'lastActivityDate', [EntityType.STATUSES]: 'lastModifiedDate', [EntityType.ISSUE_TYPES]: 'lastModifiedDate', @@ -360,18 +360,20 @@ export function buildProjectsFilter(): Array<{ field: string; op: string; value: * @returns Query filter array for time entries */ export function buildTimeEntriesFilter(yearsBack: number = 2): Array<{ field: string; op: string; value: any }> { - // TimeEntries API requires a filter. Use dateWorked to limit the range - // Calculate date from X years ago + // TimeEntries API requires a filter. Use lastModifiedDateTime so that edits + // to existing entries (e.g. hours changed, notes updated) are picked up even + // if the dateWorked is in the past or future. + // We still bound it by yearsBack to avoid a full scan on first load. const cutoffDate = new Date(); const millisecondsPerYear = 365.25 * 24 * 60 * 60 * 1000; const millisecondsBack = yearsBack * millisecondsPerYear; cutoffDate.setTime(cutoffDate.getTime() - millisecondsBack); - console.log(`TimeEntries filter: dateWorked >= ${cutoffDate.toISOString()} (${yearsBack} years back)`); + console.log(`TimeEntries filter: lastModifiedDateTime >= ${cutoffDate.toISOString()} (${yearsBack} years back)`); return [ { - field: 'dateWorked', + field: 'lastModifiedDateTime', op: 'gte', value: cutoffDate.toISOString(), },