From e3395d241f4c3aa4af9ed19793846721239efc63 Mon Sep 17 00:00:00 2001 From: iamtoruk Date: Sun, 19 Apr 2026 04:23:17 -0700 Subject: [PATCH] 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. --- src/cli.ts | 6 +++++- src/daily-cache.ts | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index 6090495..54d2a20 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -352,7 +352,11 @@ program } const gapStart = c.lastComputedDate - ? new Date(new Date(`${c.lastComputedDate}T00:00:00.000Z`).getTime() + MS_PER_DAY) + ? new Date( + parseInt(c.lastComputedDate.slice(0, 4)), + parseInt(c.lastComputedDate.slice(5, 7)) - 1, + parseInt(c.lastComputedDate.slice(8, 10)) + 1 + ) : new Date(todayStart.getTime() - BACKFILL_DAYS * MS_PER_DAY) if (gapStart.getTime() <= yesterdayEnd.getTime()) { diff --git a/src/daily-cache.ts b/src/daily-cache.ts index 11903bf..f65a9c8 100644 --- a/src/daily-cache.ts +++ b/src/daily-cache.ts @@ -4,7 +4,7 @@ import { mkdir, open, readFile, rename, unlink } from 'fs/promises' import { homedir } from 'os' import { join } from 'path' -export const DAILY_CACHE_VERSION = 2 +export const DAILY_CACHE_VERSION = 3 const DAILY_CACHE_FILENAME = 'daily-cache.json' export type DailyEntry = {