Skip to content

fix(illness): allow adding episodes before noon - #1376

Merged
MBombeck merged 1 commit into
MBombeck:mainfrom
ferges123:fix/illness-episode-dates-publish
Nov 15, 2026
Merged

MBombeck merged 1 commit into
MBombeck:mainfrom
ferges123:fix/illness-episode-dates-publish

Conversation

@ferges123

@ferges123 ferges123 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Adding an illness episode before noon could fail. The selected onset date was serialized as a local-noon timestamp, which could be later than the current time. The API then rejected the otherwise valid same-day entry as a future date.

Fix

Serialize the onset date so it stays on the selected calendar day and passes validation at any time of day.

Additional improvements

  • Preserve exact stored timestamps when editing episodes.
  • Prevent overlapping updates from being saved out of order.
  • Validate onset and resolution ordering consistently, including sub-millisecond timestamps.
  • Use the default time zone if the display time zone is temporarily empty.

Compatibility and validation

Rebased onto v1.47.5; preserves its form-dismissal protection, recovered-episode logging limit, and idempotent create requests.

@ferges123
ferges123 force-pushed the fix/illness-episode-dates-publish branch 2 times, most recently from 7690eb1 to 3e74c7b Compare November 12, 2026 21:55
@ferges123
ferges123 marked this pull request as ready for review November 12, 2026 22:20

@MBombeck MBombeck left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks again, @ferges123. You found the real cause: the form sends noon of the picked day, the schema refuses anything more than five minutes ahead, so a new episode for today fails until midday. Keeping the stored instant on edit and showing the day in the user's zone instead of slice(0, 10) are good catches too.

The fix itself is small, though, and I'd like it to stay that way. Before I merge, I'd ask for these changes:

  1. Drop new-episode-sheet.test.tsx. It mocks react and runs its own hook runtime, so it tests a fake React rather than the sheet. The browser tests already cover the real behaviour, and every refactor of the sheet would break these 1,700 lines.
  2. Remove the sub-millisecond handling in validations/illness.ts. The columns are timestamp(3) and a Date never carries more than milliseconds, so it has no case to handle. It also refuses a PATCH like onsetAt: "…12:00:00.123800Z" against a stored resolvedAt of .123Z, which used to pass. The two route tests that cover it use a Date whose toISOString() returns microseconds, which Prisma can't hand back. A plain Date.parse comparison for the end-before-start check is the part worth keeping.
  3. Remove the legacy { id, input } form of useUpdateEpisode. Nothing calls it, and with an id bound to the hook it can PATCH a different episode while queueing under the first one. The repo avoids compatibility shims for callers that don't exist.
  4. Slim the ordering machinery. The generation counter, prevOpenRef, the second effect, the midnight timer and the time zone snapshot go well beyond this bug. Blocking on isPending as before is enough. If you want scope, it should cover useResolveEpisode too, or a resolve can still race an edit.
  5. Small ones: serializeEpisodeDate can be min(noon in the zone, now) without today, since the date field already blocks future days. toLocalDateKey can use userDayKey. The timeZone || DEFAULT_TIMEZONE fallback and the typeof/trim guards never fire, because useDisplayTimezone() already falls back and the field always gives YYYY-MM-DD.
  6. Tests and changelog: episode-date-serialization.test.ts can shrink to the cases that matter (before and after noon, UTC+14, UTC-12, a DST day, keeping the stored instant, the same-day clamp). Two or three browser tests are plenty. The CHANGELOG entry should name the bug people saw: a new episode was refused in the morning.

If you'd like to do this, great. If I haven't heard back by Wednesday, 18 November, I'll make these changes on top of your branch myself and keep your commits, so it's in the next patch either way.

@ferges123
ferges123 force-pushed the fix/illness-episode-dates-publish branch from 3e74c7b to 5cdc69f Compare November 15, 2026 08:14
@ferges123
ferges123 force-pushed the fix/illness-episode-dates-publish branch from 5cdc69f to 851d52b Compare November 15, 2026 08:22
@ferges123

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I've simplified the PR as requested.

@MBombeck
MBombeck merged commit ac4a4b2 into MBombeck:main Nov 15, 2026
31 checks passed
@MBombeck

Copy link
Copy Markdown
Owner

@ferges123 Merged, thanks for slimming it down so quickly. The morning fix and the time zone handling go out with the next patch.

@MBombeck MBombeck mentioned this pull request Nov 15, 2026
@MBombeck

Copy link
Copy Markdown
Owner

@ferges123 This is out in v1.47.6, and the release notes thank you for it.

@ferges123
ferges123 deleted the fix/illness-episode-dates-publish branch November 15, 2026 14:34
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.

2 participants