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
+58
View File
@@ -30,6 +30,64 @@ void main() {
});
});
group('CalendarDayArithmetic', () {
test('addDays preserves wall-clock time on a normal day', () {
final d = DateTime(2026, 5, 18, 8, 30);
final next = d.addDays(1);
expect(next.year, 2026);
expect(next.month, 5);
expect(next.day, 19);
expect(next.hour, 8);
expect(next.minute, 30);
});
test('addDays normalises across month boundaries', () {
final d = DateTime(2026, 1, 30);
expect(d.addDays(3), DateTime(2026, 2, 2));
});
test(
'addDays(7 * N) keeps weekday across the October DST fall-back, '
'unlike Duration(days: 7 * N)',
() {
// Sep 1, 2025 is a Monday (CEST). 16 weeks later is Dec 22, 2025,
// also a Monday (CET) — but `add(Duration(days: 112))` lands at
// Sunday Dec 21 23:00 because DST drains an hour in October.
final mondayBeforeDst = DateTime(2025, 9, 1);
final mondayAfterDst = mondayBeforeDst.addDays(7 * 16);
expect(mondayAfterDst.weekday, DateTime.monday);
expect(mondayAfterDst.hour, 0);
expect(mondayAfterDst.day, 22);
expect(mondayAfterDst.month, 12);
},
// Test only meaningful when running in a DST-aware timezone (e.g.
// Europe/Berlin). In UTC `Duration` arithmetic happens to be safe
// too, so the assertion still holds; we keep it unconditional.
);
test(
'subtractDays(7) crossing March DST spring-forward stays on Monday',
() {
// Mon Apr 6 2026 (CEST, UTC+2) - 1 week should still be Mon Mar 30
// 2026 (CEST). With Duration(days:7) you'd get Mar 29 23:00 (CEST)
// - actually CET=>CEST: the transition is at 02:00 → 03:00 on
// Mar 29. Either way `addDays`/`subtractDays` must hit midnight.
final monApr6 = DateTime(2026, 4, 6);
final prev = monApr6.subtractDays(7);
expect(prev.weekday, DateTime.monday);
expect(prev.day, 30);
expect(prev.month, 3);
expect(prev.hour, 0);
expect(prev.minute, 0);
},
);
test('subtractDays(n) is equivalent to addDays(-n)', () {
final d = DateTime(2026, 5, 18, 13, 45);
expect(d.subtractDays(5), d.addDays(-5));
});
});
group('DateTimeFormatting', () {
final dt = DateTime(2026, 5, 8, 9, 7);