fix(db): decode creationDate/stopDate as Unix epoch, not Core Data - #127
Merged
Conversation
Things stores its absolute-timestamp REAL columns (creationDate, stopDate) as seconds since the Unix epoch, but they were decoded against Apple's Core Data reference date (2001-01-01), shifting every value exactly +31 years into the future (e.g. a task created 2026-08-09 reported creationDate 2057-08-09). Anything sorting or filtering on those fields via JSON output would misbehave. Replace CoreDataToTime/TimeToCoreData with UnixToTime/TimeToUnix — an audit of call sites shows no column in the Things schema actually uses the 2001 epoch (startDate/deadline use the separate ThingsDate bit-encoding), so the old codec is deleted rather than kept alongside. The logbook manualLogDate comparison is column-vs-column in the same epoch and is unaffected. Adds a regression test pinning a real TMTask creationDate value to its correct 2026 decode.
Truncation could land one nanosecond short of the stored value due to float64 representation (0.119778s -> 119777999ns); round instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
things search --json(and every other JSON output path) reportedcreationDate/stopDateexactly +31 years in the future — a task created2026-08-09T00:23:25ZemittedcreationDate: 2057-08-09T00:23:25Z.Root cause
Things stores its absolute-timestamp REAL columns (
TMTask.creationDate,stopDate, checkliststopDate) as seconds since the Unix epoch (1970), butinternal/dbdecoded them withmodel.CoreDataToTime, which adds the value to Apple's Core Data reference date (2001-01-01). A 1970-based value fed into a 2001-based decoder lands exactly 31 years late.Verified against the live DB (read-only):
Fix
CoreDataToTime/TimeToCoreDatawithUnixToTime/TimeToUnix. A call-site audit shows no column in the Things schema actually uses the 2001 epoch —startDate/deadlineuse the separate ThingsDate bit-encoding — so the old codec is deleted outright rather than kept as a second decoder.stopDate > manualLogDatefilter compares column-vs-column in the same epoch, so it was never affected.TMTask.creationDatevalue (1786235005.119778) to its correct 2026 decode; the round-trip and epoch-zero tests now assert against 1970.Verification
make test,make lint,make buildall clean. Rebuilt binary against the live DB: the exact task from the bug report (7vyrVUfNGFgcPq6Q5uv6vb) now emitscreationDate: 2026-08-09T00:23:25Z.