import 'package:flutter_test/flutter_test.dart'; import 'package:jiffy/jiffy.dart'; import 'package:marianum_mobile/extensions/date_time.dart'; void main() { setUpAll(() async { // Jiffy needs locale data once before any formatting calls. await Jiffy.setLocale('de'); }); group('IsSameDay', () { test('isSameDay matches by year/month/day, ignoring time', () { final a = DateTime(2026, 5, 8, 9, 30); final b = DateTime(2026, 5, 8, 22, 0); expect(a.isSameDay(b), isTrue); }); test('isSameDay differs across midnight', () { final a = DateTime(2026, 5, 8, 23, 59); final b = DateTime(2026, 5, 9, 0, 0); expect(a.isSameDay(b), isFalse); }); test('isSameOrAfter is inclusive', () { final a = DateTime(2026, 5, 8, 12); final b = DateTime(2026, 5, 8, 12); expect(a.isSameOrAfter(b), isTrue); expect(a.add(const Duration(seconds: 1)).isSameOrAfter(b), isTrue); expect(a.subtract(const Duration(seconds: 1)).isSameOrAfter(b), isFalse); }); }); group('DateTimeFormatting', () { final dt = DateTime(2026, 5, 8, 9, 7); test('formatHm pads hours and minutes to two digits', () { expect(dt.formatHm(), '09:07'); }); test('formatDate uses dd.MM.yyyy', () { expect(dt.formatDate(), '08.05.2026'); }); test('formatDateTime combines date and time', () { expect(dt.formatDateTime(), '08.05.2026 09:07'); }); test('formatDateShort drops the year', () { expect(dt.formatDateShort(), '08.05.'); }); test('formatDateShortHm combines short date and time', () { expect(dt.formatDateShortHm(), '08.05. 09:07'); }); test('timeRangeTo joins start and end with a hyphen', () { final end = dt.add(const Duration(minutes: 45)); expect(dt.timeRangeTo(end), '09:07 - 09:52'); }); }); }