Skip to content

Commit e3395d2

Browse files
committed
Fix daily cache gap fill using UTC instead of local time
The gapStart date was constructed with T00:00:00.000Z (UTC midnight), causing it to land hours before local midnight. In PDT this meant the gap fill re-parsed a partial slice of the previous day, and the upsert replaced the full day with that partial data, losing cost. Bump DAILY_CACHE_VERSION to 3 to force cache rebuild.
1 parent 070a378 commit e3395d2

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/cli.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,11 @@ program
352352
}
353353

354354
const gapStart = c.lastComputedDate
355-
? new Date(new Date(`${c.lastComputedDate}T00:00:00.000Z`).getTime() + MS_PER_DAY)
355+
? new Date(
356+
parseInt(c.lastComputedDate.slice(0, 4)),
357+
parseInt(c.lastComputedDate.slice(5, 7)) - 1,
358+
parseInt(c.lastComputedDate.slice(8, 10)) + 1
359+
)
356360
: new Date(todayStart.getTime() - BACKFILL_DAYS * MS_PER_DAY)
357361

358362
if (gapStart.getTime() <= yesterdayEnd.getTime()) {

src/daily-cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { mkdir, open, readFile, rename, unlink } from 'fs/promises'
44
import { homedir } from 'os'
55
import { join } from 'path'
66

7-
export const DAILY_CACHE_VERSION = 2
7+
export const DAILY_CACHE_VERSION = 3
88
const DAILY_CACHE_FILENAME = 'daily-cache.json'
99

1010
export type DailyEntry = {

0 commit comments

Comments
 (0)