fix: unify date limits, fix ISO week calculation, refactor home screen plan button
- Fix _isoWeek: correct Sunday shift (-3 instead of +4), use floor+1 formula, match jan1 timezone to input — planned meals now appear correctly for UTC+ users - Add kPlanningHorizonDays=28 / kMenuPastWeeks=8 constants; apply to home date strip, plan picker (strip + calendar), and menu screen prev/next navigation - Menu screen week nav: disable arrows at min/max limits using compareTo - Home screen: replace _GenerateActionCard/_WeekPlannedChip conditional with always-visible _FutureDayPlanButton(dateString); show _DayPlannedChip only when the specific day has planned meals; remove standalone _PlanMenuButton - _FutureDayPlanButton uses selected date as defaultStart instead of lastPlanned+1 - Rename weekPlannedLabel -> dayPlannedLabel across all 12 locales Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -16,22 +16,27 @@ final menuServiceProvider = Provider<MenuService>((ref) {
|
||||
|
||||
/// The ISO week string for the currently displayed week, e.g. "2026-W08".
|
||||
final currentWeekProvider = StateProvider<String>((ref) {
|
||||
final now = DateTime.now().toUtc();
|
||||
final now = DateTime.now();
|
||||
final (y, w) = _isoWeek(now);
|
||||
return '$y-W${w.toString().padLeft(2, '0')}';
|
||||
});
|
||||
|
||||
(int year, int week) _isoWeek(DateTime dt) {
|
||||
// Shift to Thursday to get ISO week year.
|
||||
final thu = dt.add(Duration(days: 4 - (dt.weekday == 7 ? 0 : dt.weekday)));
|
||||
final jan1 = DateTime.utc(thu.year, 1, 1);
|
||||
final week = ((thu.difference(jan1).inDays) / 7).ceil();
|
||||
// Shift to Thursday of the same ISO week.
|
||||
// Monday=1…Saturday=6 → add (4 - weekday) days; Sunday=7 → subtract 3 days.
|
||||
final int shift = dt.weekday == 7 ? -3 : 4 - dt.weekday;
|
||||
final thu = dt.add(Duration(days: shift));
|
||||
// Use the same timezone as the input to avoid offset drift on the difference.
|
||||
final jan1 = dt.isUtc
|
||||
? DateTime.utc(thu.year, 1, 1)
|
||||
: DateTime(thu.year, 1, 1);
|
||||
final week = (thu.difference(jan1).inDays ~/ 7) + 1;
|
||||
return (thu.year, week);
|
||||
}
|
||||
|
||||
/// Returns the ISO 8601 week string for [date], e.g. "2026-W12".
|
||||
String isoWeekString(DateTime date) {
|
||||
final (year, week) = _isoWeek(date.toUtc());
|
||||
final (year, week) = _isoWeek(date);
|
||||
return '$year-W${week.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user