durationToLocalMidnight function
Time remaining until DEVICE-LOCAL midnight daysLeft days from today.
Used for the Season / weekly tournament end countdown. The end timestamp
is built from LOCAL DATE COMPONENTS (DateTime(year, month, day + daysLeft)) — matching how todayEpochDay computes it (also by local
date). The end timestamp used to be reconstructed with UTC midnight
(endDay * 86400000) while epoch-day was local → off by exactly the
timezone offset (UTC+7 → the countdown jumps to 00:00:00 7 hours early).
Dart normalizes an overflowing day automatically (e.g. 35 → next month).
Implementation
Duration durationToLocalMidnight(DateTime now, int daysLeft) {
final end = DateTime(now.year, now.month, now.day + daysLeft);
final ms = end.millisecondsSinceEpoch - now.millisecondsSinceEpoch;
return ms <= 0 ? Duration.zero : Duration(milliseconds: ms);
}