Skip to content

Incorrect Time Entry Sorting Due to Local Timezone Storage #62

@DylanDevelops

Description

@DylanDevelops

The problem

tmpo stores timestamps in the SQLite database using the local system time (including the timezone offset) via time.Now(). Because SQLite uses lexicographical string comparison for queries, changing the system timezone causes entries to be sorted and filtered incorrectly.

For example, an entry created at 19:00-05:00 is lexicographically "smaller" than 20:00+00:00, even though the first time is actually 4 hours later in absolute time. This leads to tmpo stats and tmpo log returning incorrect results (e.g., missing entries for "today") when the user travels or changes timezones.

Release version

0.4.1 (01-06-2026)

Operating system

Windows 11

Steps to reproduce the behavior

  1. Set your system timezone to UTC-5 (e.g., America/New_York).
  2. Run tmpo start to create an entry, wait a moment, then tmpo stop.
  3. Change your system timezone to UTC.
  4. Run tmpo stats --today.
  5. Observe that the entry created in step 2 is missing from the statistics because the string comparison logic fails to account for the timezone offset difference.

Screenshots

No response

Additional context

Root Cause:
The CreateEntry function in internal/storage/db.go uses time.Now() which persists the local offset. SQLite's BETWEEN and ORDER BY clauses operate on these strings directly.

Proposed Solution:
Modify internal/storage/db.go to always store timestamps in UTC (using time.Now().UTC()). The UI layer should handle converting these UTC timestamps back to the user's local time for display purposes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: awaiting triageWaiting for an issue to be addressed.type: bugAn issue that contains a bug report.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions