2 ms·
First, thanks for this mental model; I've got a project with iCals where I haven't been happy with the logic, and maybe I can clean it up with this! But I don't
by toast0 2y ago
First, thanks for this mental model; I've got a project with iCals where I haven't been happy with the logic, and maybe I can clean it up with this! But I don't think the text matches the examples...
This seems like an error?
> (day-of-month 12 2018-01-14) = 2018-02-14
> // 2018-01-12 is the closest 12th day of month starting from 2018-01-14 (-2d),
> // but that corresponds to a negative span, so we jump to the next month
Shouldn't the nearest 12th day of the month after the 14th of January be 2018-02-12 ?
> Rule::DayOfMonth(31)
> .next(date("2018-02-14"))
> ... will say 2018-03-03 - which is legal, because the actual next occurrence happens on 2018-03-31, for which 2018-03-03 is a valid underapproximation.
But I would expect curr.last_of_month().tomorrow().unwrap(), to return 2018-03-01 ???
- Patryk27 2y ago> Shouldn't the nearest 12th day of the month after the 14th of January be 2018-02-12 ? You're right, thanks - fixed! Small typos like those are the hill I'll die on. > But I would expect curr.last_of_month().tomorrow().unwrap(), to return 2018-03-01 ??? This case actually matches the `Ordering::Less` branch (14 < 31), so it hits this arm: Ordering::Less => curr + Span::new().days(day - curr.day()), ... yielding this calculation: 2018-02-14 + (31 - 14) = 2018-03-03 Since the actual next occurrence is on 2018-03-31, 2018-03-03 is a valid guess (just a suboptimal one). I've rephrased this section in the article to show the calculation more clearly now.