Skip to content

Keep a NavigationState's CreatedAt through a JSON round trip [minor] - #70

Merged
matt-edmondson merged 1 commit into
mainfrom
claude/navigation-62-state-created-at
Sep 29, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
claude/navigation-62-state-created-at

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #62

What was wrong

The [JsonConstructor] overload of NavigationState<T> took only items and currentIndex. It chained to the public constructor, which sets CreatedAt = DateTime.UtcNow. JsonFilePersistenceProvider writes createdAt to disk, but loading ignored it, so a restored state reported the time it was loaded rather than the time it was saved.

Change

This mirrors the fix for NavigationItem in #65.

  • A new [JsonConstructor] overload, NavigationState(IReadOnlyList<T> items, int currentIndex, DateTime createdAt), keeps createdAt when it is not the default value.
  • The existing (IReadOnlyList<T>, int) constructor stays public but loses the attribute, so no caller breaks. Adding a public constructor is why this is [minor].
  • The public (IEnumerable<T>, int) constructor still stamps DateTime.UtcNow.

Tests

Two tests are added to JsonFilePersistenceProviderTests:

  • LoadStateAsync_KeepsSavedStateCreatedAt loads a file with a known createdAt of 2020-01-01 and asserts that value.
  • SaveThenLoad_KeepsStateCreatedAt saves a state, waits, loads it, and asserts that CreatedAt equals the saved value.

Both fail with the fix reverted. With the fix, the full suite passes (dotnet test: 20 passed, 0 failed), and Navigation.csproj builds with 0 warnings.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EdrcmpMTNHSnACRgnNGs8v


Generated by Claude Code

The JSON constructor took only items and currentIndex, so the createdAt that
JsonFilePersistenceProvider writes was ignored and a loaded state reported the
time it was loaded.

A new JSON constructor takes createdAt and keeps it when it is set. The
existing (IReadOnlyList<T>, int) constructor stays, without the attribute.

Fixes #62

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EdrcmpMTNHSnACRgnNGs8v
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit b1ad873 into main Sep 29, 2026
12 checks passed
@matt-edmondson
matt-edmondson deleted the claude/navigation-62-state-created-at branch September 29, 2026 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NavigationState.CreatedAt reports the load time after a JSON round trip, not when the state was saved

2 participants