implemented DST-safe date arithmetic with new addDays and subtractDays extensions, updated timetable state to reset view and scroll boundaries on initialization to prevent stale views, added hard caps to calendar navigation, and updated version to 1.0.3+52

This commit is contained in:
2026-05-22 15:08:30 +02:00
parent f185b3273a
commit 2858f910c9
10 changed files with 158 additions and 61 deletions
+22 -1
View File
@@ -6,7 +6,7 @@ extension IsSameDay on DateTime {
year == other.year && month == other.month && day == other.day;
DateTime nextWeekday(int day) =>
add(Duration(days: (day - weekday) % DateTime.daysPerWeek));
addDays((day - weekday) % DateTime.daysPerWeek);
DateTime withTime(TimeOfDay time) =>
copyWith(hour: time.hour, minute: time.minute);
@@ -23,6 +23,27 @@ extension IsSameDay on DateTime {
bool isSameOrAfter(DateTime other) => isSameDateTime(other) || isAfter(other);
}
/// Calendar-aware day arithmetic. `DateTime.add(Duration(days: n))` adds
/// `n * 24h` of real-world time, which on local DateTimes silently drifts by
/// ±1h across DST transitions — so 7 days from "Monday 00:00 CEST" before a
/// DST fall-back lands at "Sunday 23:00 CET", shifting the entire next week
/// onto the wrong calendar day. [addDays]/[subtractDays] normalize through
/// `DateTime(year, month, day + n)` so the wall-clock fields stay fixed.
extension CalendarDayArithmetic on DateTime {
DateTime addDays(int days) => DateTime(
year,
month,
day + days,
hour,
minute,
second,
millisecond,
microsecond,
);
DateTime subtractDays(int days) => addDays(-days);
}
/// Formatting helpers backed by Jiffy. Centralises the patterns that previously
/// were repeated as `Jiffy.parseFromDateTime(dt).format(pattern: '...')`.
extension DateTimeFormatting on DateTime {