Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions src/commands/statusline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,19 @@ export const statuslineCommand = define({
const today = new Date();
const todayStr = today.toISOString().split('T')[0]?.replace(/-/g, '') ?? ''; // Convert to YYYYMMDD format

// Only process files modified after midnight today for daily data
const midnightToday = new Date();
midnightToday.setHours(0, 0, 0, 0);

Comment on lines +306 to +309
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Timezone consistency for “today” filter.

todayStr uses UTC (toISOString) while daily grouping uses local/system timezone. Compute todayStr via formatDate with the same timezone, and pass timezone into data loader calls.

- // Only process files modified after midnight today for daily data
- const midnightToday = new Date();
- midnightToday.setHours(0, 0, 0, 0);
+ // Only process files modified after midnight today (in configured timezone if provided)
+ const midnightToday = new Date();
+ midnightToday.setHours(0, 0, 0, 0);
-            try: async () => loadDailyUsageData({
-              since: todayStr,
-              until: todayStr,
-              mode: 'auto',
-              offline: mergedOptions.offline,
-              minUpdateTime: midnightToday,
-              includeContent: false,
-            }),
+            try: async () => loadDailyUsageData({
+              since: /* computed via formatDate to match timezone */ todayStr,
+              until: /* computed via formatDate to match timezone */ todayStr,
+              mode: "auto",
+              offline: mergedOptions.offline,
+              timezone: mergedOptions.timezone,
+              minUpdateTime: midnightToday,
+              includeContent: false,
+            }),

Outside this hunk, update todayStr and imports (supporting change):

- const today = new Date();
- const todayStr = today.toISOString().split('T')[0]?.replace(/-/g, '') ?? '';
+ // Keep “today” consistent with the same timezone used by data loader
+ import { formatDate } from "../_date-utils.ts";
+ import { DEFAULT_LOCALE } from "../_consts.ts";
+ const today = new Date();
+ const todayStr = formatDate(today.toISOString(), mergedOptions.timezone, DEFAULT_LOCALE).replace(/-/g, "");

Also applies to: 317-319

🤖 Prompt for AI Agents
In src/commands/statusline.ts around lines 306-309 (and also apply the same
change at 317-319), the code computes midnightToday/local daily grouping but
constructs todayStr using toISOString/UTC which causes timezone mismatch; change
todayStr to use the existing formatDate helper (or import it if missing) with
the same timezone used for grouping so the "today" filter is computed in the
local/system timezone, and update the data loader calls to accept and pass that
timezone parameter; also add/adjust imports for formatDate/timezone utilities as
required and ensure the timezone value is forwarded into all relevant loader
function calls.

const todayCost = await Result.pipe(
Result.try({
try: async () => loadDailyUsageData({
since: todayStr,
until: todayStr,
mode: 'auto',
offline: mergedOptions.offline,
minUpdateTime: midnightToday,
includeContent: false,
}),
catch: error => error,
})(),
Expand All @@ -325,11 +331,16 @@ export const statuslineCommand = define({
);

// Load session block data to find active block
// Only process files modified in the last 6 hours for block data
// This ensures we capture the current blocks without processing all historical data
const sixHoursAgo = new Date(Date.now() - 6 * 60 * 60 * 1000);

const { blockInfo, burnRateInfo } = await Result.pipe(
Result.try({
try: async () => loadSessionBlockData({
mode: 'auto',
offline: mergedOptions.offline,
minUpdateTime: sixHoursAgo,
}),
catch: error => error,
})(),
Expand Down
Loading