An automatic repricing tool lets a seller keep one set of pricing rules per age of a listing. The default sets are named by their range: "0-30 days", "31-90 days", "91-180 days", "181-365 days" and "Over 1 year".
Each set carries its own safety limit, the drop limit. For example: "never drop a price by more than 10% in one run". One seller set exactly that on the youngest set, and on day 30 an item dropped by more.
Key facts
- The set names count both ends: "0-30" ends on day 30, and "31-90" starts on day 31.
- The stored numbers are shared edges: (0, 30), (30, 90), (90, 180), (180, 365), (365, none).
- The code matched with
age >= min && age < max, so day 30 went to the set labelled "31-90 days". The same happened on days 90, 180 and 365. - One item went from $11.40 to $9.99 on day 30, a 12.4% drop. Its seller's limit was 10%; the next set allowed 20%.
- Found from one support mail, fixed the same day. Three comparisons changed; the stored numbers did not.
What happened
The seller wrote to support: "I set 10%, why did it drop more?" The young set had a 10% drop limit. The item had moved from $11.40 to $9.99, a 12.4% drop, in one run.
Every setting on their screen was right. The item was 30 days old, and the screen said the "0-30 days" set covers day 30. But the code had priced it with the next set, "31-90 days", whose drop limit was 20%. A 12.4% drop is well inside 20%, so as far as the code knew, nothing was wrong.
The screen and the code disagreed about one day. On each edge day, 30, 90, 180 and 365, a listing was priced by the next, older set, one day earlier than the label promised. Older sets are usually the more aggressive ones, so the error leaned toward bigger drops.
One range, two owners
A range has two owners: the label a person reads, and the comparison the code runs. They follow different habits.
People count both ends. "0-30 days" includes day 30, and "31-90 days" starts the day after.
Programmers usually count the start and leave out the end: "from min, up to but not including max". That is a good habit. With shared edges, it puts every day in exactly one set, with no gaps and no overlaps. The code here did exactly that.
The trouble is the meeting point. When one stored number, 30, is both the end of one set and the start of the next, the edge day belongs to whichever side the code picks. The label named one side; the code picked the other. Neither was wrong on its own. They just never agreed.
Why nothing failed
Nothing crashed, and no test went red. Every age still landed in exactly one set, and every set still applied its own limit correctly. The only wrong thing was which set, on four edge days in a listing's life.
The tests checked typical ages, like day 12 or day 45. On those days both readings give the same answer, so the tests could never see the edge. Like a safety check that silently did not apply, the limit here looked on and worked as written, just on the wrong item.
The fix
The stored numbers stayed as they were, so no data migration was needed. Only the comparison moved, toward the younger set, so that it matches the label. A sketch, with made-up names:
const SETS = [[0, 30], [30, 90],
[90, 180], [180, 365],
[365, Infinity]];
// Before: start in, end out.
function pickSet(age: number) {
return SETS.find(([min, max]) =>
age >= min && age < max);
}
// pickSet(30): the "31-90 days" set
// After: both ends, like the label.
function pickSet(age: number) {
return SETS.find(([min, max]) =>
min === 0
? age <= max
: age > min && age <= max);
}
// pickSet(30): the "0-30 days" set
// Edge tests: each edge e and e+1.
const EDGE_CASES = [
[30, "0-30 days"],
[31, "31-90 days"],
[90, "31-90 days"],
[91, "91-180 days"],
[180, "91-180 days"],
[181, "181-365 days"],
[365, "181-365 days"],
[366, "Over 1 year"],
];
The same comparison had been copied to two more places: the report that groups stock by age, and the filter on the stock page. So the fix changed three comparisons, not one.
The screen changed too. The grey line under each set now says in plain words what it takes: "Listed up to 30 days", "Listed 31-90 days", and so on.
Here is what the eight edge cases look like before and after:
| Listing age | Set before the fix | Set after the fix |
|---|---|---|
| Day 30 | 31-90 days | 0-30 days |
| Day 31 | 31-90 days | 31-90 days |
| Day 90 | 91-180 days | 31-90 days |
| Day 91 | 91-180 days | 91-180 days |
| Day 180 | 181-365 days | 91-180 days |
| Day 181 | 181-365 days | 181-365 days |
| Day 365 | Over 1 year | 181-365 days |
| Day 366 | Over 1 year | Over 1 year |
The checklist
Anyone who stores ranges and shows them to people can do these tomorrow:
- Decide the edge once, in words. Write it next to the stored numbers: "a pair (min, max) takes day min+1 through day max; a pair starting at 0 also takes day 0".
- Let the label come from the matching code. Generate it from the same function that picks the set, or print under each set the plain sentence of what it takes, like "Listed up to 30 days".
- Test the edges by name. For every stored edge e, assert which set e and e+1 land in. Four edges, eight asserts. Tests on typical values never see this.
- Search for the copies. The same range logic usually lives in the report, the filter and the worker too. Use one shared function, or run the same edge tests against each copy.
- Check the bucket before the maths. When a customer says "the limit I set was not respected", first check which set the item was in at that moment. Then check the limit.
The lesson in one line: when stored numbers are shared edges, the edge day belongs to whichever side the code picks, not the side the label names, and nothing fails to tell you.
Common questions
Why not change the stored numbers instead?
You could store (0, 30), (31, 90) and so on. Then the sets no longer share edges, and every later edit has to avoid leaving a gap or an overlap. Moving the comparison kept the stored numbers as they were, so no data had to change.
Is "start in, end out" wrong?
No. It is a good default, and it puts every day in exactly one set. The trouble starts only when the label a person reads counts both ends and the code does not. Pick one rule and make the label follow it.
Why did no test catch it?
The tests used typical ages, like day 12 or day 45, well inside a set. Both readings agree on those days. They disagree only on the four edge days, and no test named one.
Melta is free; get it on the App Store or Google Play.