Repository navigation
fix(illness): allow adding episodes before noon - #1376
Conversation
7690eb1 to
3e74c7b
Compare
MBombeck
left a comment
There was a problem hiding this comment.
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:
- Drop
new-episode-sheet.test.tsx. It mocksreactand 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. - Remove the sub-millisecond handling in
validations/illness.ts. The columns aretimestamp(3)and aDatenever carries more than milliseconds, so it has no case to handle. It also refuses a PATCH likeonsetAt: "…12:00:00.123800Z"against a storedresolvedAtof.123Z, which used to pass. The two route tests that cover it use aDatewhosetoISOString()returns microseconds, which Prisma can't hand back. A plainDate.parsecomparison for the end-before-start check is the part worth keeping. - Remove the legacy
{ id, input }form ofuseUpdateEpisode. 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. - 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 onisPendingas before is enough. If you wantscope, it should coveruseResolveEpisodetoo, or a resolve can still race an edit. - Small ones:
serializeEpisodeDatecan bemin(noon in the zone, now)withouttoday, since the date field already blocks future days.toLocalDateKeycan useuserDayKey. ThetimeZone || DEFAULT_TIMEZONEfallback and thetypeof/trimguards never fire, becauseuseDisplayTimezone()already falls back and the field always givesYYYY-MM-DD. - Tests and changelog:
episode-date-serialization.test.tscan 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.
3e74c7b to
5cdc69f
Compare
5cdc69f to
851d52b
Compare
|
Thanks for the review. I've simplified the PR as requested. |
|
@ferges123 Merged, thanks for slimming it down so quickly. The morning fix and the time zone handling go out with the next patch. |
|
@ferges123 This is out in v1.47.6, and the release notes thank you for it. |
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
Compatibility and validation
Rebased onto
v1.47.5; preserves its form-dismissal protection, recovered-episode logging limit, and idempotent create requests.