Skip to content

fix(usage): Usage tab displays dates in UTC instead of user's local timezone #3085

@IamCoder18

Description

@IamCoder18

Summary

The usage tab displays usage data grouped by UTC dates instead of the user's local timezone. This affects both "By Day" and "By Model & Day" views, as well as the streak calculation and streak calendar.

Affected Components

  • Usage tab "By Day" view
  • Usage tab "By Model & Day" view
  • Streak calculation
  • Streak calendar

Problem

When viewing usage data, dates are grouped by UTC day rather than the user's local day. For example, a user in PST (UTC-8) coding at 8 PM will have their usage recorded as occurring on the next day in UTC.

Possible root cause: The API route /api/profile/usage/route.ts uses DATE(created_at) which extracts the date in the database's timezone (UTC), and the streak calculation uses JavaScript's toISOString() which always returns UTC.

Steps to Reproduce

  1. Set browser timezone to a non-UTC timezone (e.g., PST, EST)
  2. Navigate to the usage tab
  3. View "By Day" or "By Model & Day" view
  4. Observe that dates shown don't match local date boundaries

Expected Behavior

  • Usage data should be grouped by the user's local date
  • Streak calculation should count consecutive days in the user's local timezone
  • Streak calendar should display dates in the user's local timezone

Actual Behavior

  • Usage data is grouped by UTC date
  • Streak calculation uses UTC-based date comparison
  • Dates displayed don't match user's local date boundaries

Possible Root Causes

  • API route uses DATE(created_at) PostgreSQL function without timezone conversion
  • Client-side streak calculation uses toISOString().split('T')[0] which is UTC-based
  • Browser timezone is not detected or passed to the API

Environment

  • Component: Usage tab (/app/(app)/usage/page.tsx)
  • API: /api/profile/usage/route.ts
  • Database: PostgreSQL with microdollar_usage table

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions