▲ | toast0 2 days 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 2 days ago | parent [-] | |
> 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:
... yielding this calculation:
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. |