Opening hours with a discount cannot be parsed back #4

Closed
opened 2026-10-10 17:01:53 +02:00 by pepa · 0 comments
Owner

Found while writing unit tests (#2).

Problem

DayHours Display renders an interval with a discount as 08:00 - 09:00 (10), and RE_HOURS accepts that format, but DayHour::try_from does not parse it — it fails with HourParseError and never sets discount (it is always None).

Verified: 08:00 - 09:00 (10) passes WeekHours::validate() and fails DayHours::try_new().

Impact

Currently latent: a discount cannot be entered through the UI, so opening_hour.discount is normally NULL. As soon as a row has a discount, the edit dialog is pre-filled with the (10) suffix and saving it fails with a server error. update_hours also deletes and re-inserts the rows, so even without the error the discount could not survive an edit.

Suggested fix

Teach DayHour::try_from to parse the optional (N) suffix into discount, and add a round-trip unit test with a discount (the existing day_hours_display_round_trip covers only intervals without one). Alternatively, if discounts per interval are not a planned feature, remove them from Display and from the regex.

Found while writing unit tests (#2). ## Problem `DayHours` `Display` renders an interval with a discount as `08:00 - 09:00 (10)`, and `RE_HOURS` accepts that format, but `DayHour::try_from` does not parse it — it fails with `HourParseError` and never sets `discount` (it is always `None`). Verified: `08:00 - 09:00 (10)` passes `WeekHours::validate()` and fails `DayHours::try_new()`. ## Impact Currently latent: a discount cannot be entered through the UI, so `opening_hour.discount` is normally `NULL`. As soon as a row has a discount, the edit dialog is pre-filled with the `(10)` suffix and saving it fails with a server error. `update_hours` also deletes and re-inserts the rows, so even without the error the discount could not survive an edit. ## Suggested fix Teach `DayHour::try_from` to parse the optional `(N)` suffix into `discount`, and add a round-trip unit test with a discount (the existing `day_hours_display_round_trip` covers only intervals without one). Alternatively, if discounts per interval are not a planned feature, remove them from `Display` and from the regex.
pepa closed this issue 2026-10-11 17:09:45 +02:00
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ITsolved/rezervovator#4