setWeekYear method
Returns a new Hora set to the same week in a different week year.
Implementation
Hora setWeekYear(int year, [WeekYearConfig config = WeekYearConfig.iso]) {
final currentWeek = weekOfWeekYear(config);
final currentWeekday = _adjustedWeekday(config);
// Find the first week of the target year
final firstWeekThursday = _firstWeekThursday(year, config);
final firstWeekStart = firstWeekThursday.subtract(
Duration(days: (firstWeekThursday.weekday - config.weekStart + 7) % 7),
);
// Calculate the target date
final targetDate = firstWeekStart.add(
Duration(days: (currentWeek - 1) * 7 + currentWeekday),
);
return copyWith(
year: targetDate.year,
month: targetDate.month,
day: targetDate.day,
);
}