replace method
Returns a new date with one or more fields replaced. Uses the largest valid day if the resulting month is shorter.
var date = LocalDate(2000, 1, 31);
date.replace(month: 4) == LocalDate(2001, 4, 30);
Implementation
LocalDate replace({int? year, int? month, int? day}) {
year ??= this.year;
month ??= this.month;
day ??= this.day;
day = min(day, daysInMonth(year, month));
return LocalDate(year, month, day);
}