implemented short relative date formatting for chat and added unit tests

This commit is contained in:
2026-05-09 22:23:25 +02:00
parent 4c190de479
commit 7d02e70459
3 changed files with 64 additions and 1 deletions
+49
View File
@@ -58,4 +58,53 @@ void main() {
expect(dt.timeRangeTo(end), '09:07 - 09:52');
});
});
group('formatDateRelativeShort', () {
final now = DateTime(2026, 5, 9, 14, 0); // Saturday
test('today returns "Heute"', () {
expect(
DateTime(2026, 5, 9, 8, 0).formatDateRelativeShort(now: now),
'Heute',
);
});
test('yesterday returns "Gestern"', () {
expect(
DateTime(2026, 5, 8, 23, 30).formatDateRelativeShort(now: now),
'Gestern',
);
});
test('2 to 6 days ago returns the German weekday name', () {
// 2026-05-07 is a Thursday
expect(
DateTime(2026, 5, 7).formatDateRelativeShort(now: now),
'Donnerstag',
);
// 2026-05-03 is a Sunday (6 days before Saturday 9th)
expect(
DateTime(2026, 5, 3).formatDateRelativeShort(now: now),
'Sonntag',
);
});
test('7 days or more ago falls back to dd.MM.yyyy', () {
expect(
DateTime(2026, 5, 2).formatDateRelativeShort(now: now),
'02.05.2026',
);
expect(
DateTime(2026, 1, 1).formatDateRelativeShort(now: now),
'01.01.2026',
);
});
test('future dates fall back to dd.MM.yyyy', () {
expect(
DateTime(2026, 5, 10).formatDateRelativeShort(now: now),
'10.05.2026',
);
});
});
}