Hi everyone!
While mentoring this exercise and revisiting my own solution, I found a bug that isn’t caught by the current test suite: quarter-based deliveries incorrectly roll over to the next year even when the start date is still inside the target quarter — specifically, when the start date falls in the target quarter’s own last month (March for Q1, June for Q2, September for Q3, December for Q4).
Why this is worth a test
This is a classic off-by-one/fencepost bug, and it’s easy to introduce in more than one way. In my own solution, it came from an inclusive comparison (start.month >= des * 3 instead of >) that swept the boundary month into the wrong branch. Looking at community solutions, I found a second, differently-shaped implementation that hit the exact same boundary via a different mechanism — a quarter-from-month formula that assumed 0-indexed months (month // 3 + 1 instead of (month - 1) // 3 + 1), which also misclassifies exactly the last month of each quarter.
Two independently-written solutions, using unrelated logic, made the same mistake at the same boundary — and both passed all 16 existing canonical tests. That’s because none of the three current quarter tests start in the last month of the quarter being requested:
Q1test starts in January (Q1’s first month)Q4test starts in April (unrelated quarter)Q3test starts in October (unrelated quarter)
None of them exercise “am I still inside the target quarter” at the one point where that logic is actually hard to get right.
Suggested test
{
"uuid": "to-be-defined",
"description": "Q2 starting in the last month of the second quarter translates to the last workday of the second quarter of this year",
"property": "deliveryDate",
"input": {
"meetingStart": "2019-06-15T09:30:00",
"description": "Q2"
},
"expected": "2019-06-28T08:00:00"
}
Happy to adjust the description string or pick a different date if there’s a preference for consistency with the existing test names. Is this worth adding to the canonical data?