share weekKey extension and log splash precache failures

This commit is contained in:
2026-07-12 23:56:47 +02:00
parent f50359b4eb
commit 53bc6d5360
5 changed files with 15 additions and 10 deletions
+3
View File
@@ -64,6 +64,9 @@ extension DateTimeFormatting on DateTime {
String formatRelative() => Jiffy.parseFromDateTime(this).fromNow();
/// Compact `yyyyMMdd` key, e.g. to identify a week-start in timetable caches.
String weekKey() => Jiffy.parseFromDateTime(this).format(pattern: 'yyyyMMdd');
String timeRangeTo(DateTime end) => '${formatHm()} - ${end.formatHm()}';
String formatDateRelativeShort({DateTime? now}) {
@@ -1,7 +1,5 @@
import 'dart:developer';
import 'package:intl/intl.dart';
import '../../../../../api/marianumconnect/queries/timetable_get_element_week/timetable_element_type.dart';
import '../../../../../api/marianumconnect/queries/timetable_get_week/timetable_get_week_response.dart';
import '../../../../../extensions/date_time.dart';
@@ -24,7 +22,6 @@ class ForeignTimetableBloc
TimetableState,
ForeignTimetableRepository
> {
static final DateFormat _weekKeyFormat = DateFormat('yyyyMMdd');
final TimetableElementType type;
// Named `elementId` rather than `id` to avoid shadowing HydratedMixin's
@@ -183,7 +180,7 @@ class ForeignTimetableBloc
}
void _writeWeekToCache(DateTime weekStart, TimetableGetWeekResponse week) {
final key = _weekKeyFormat.format(weekStart);
final key = weekStart.weekKey();
add(
Emit((s) {
final updated = Map<String, TimetableGetWeekResponse>.of(s.weekCache);
@@ -1,7 +1,5 @@
import 'dart:developer';
import 'package:intl/intl.dart';
import '../../../../../api/marianumconnect/queries/timetable_custom_events/custom_events_migration.dart';
import '../../../../../api/marianumconnect/queries/timetable_get_week/timetable_get_week_response.dart';
import '../../../../../api/mhsl/custom_timetable_event/custom_timetable_event.dart';
@@ -19,8 +17,6 @@ class TimetableBloc
TimetableState,
TimetableRepository
> {
static final DateFormat _weekKeyFormat = DateFormat('yyyyMMdd');
DateTime _lastWeekRequestStart = DateTime.fromMillisecondsSinceEpoch(0);
/// Set by [retry] to force the next [gatherData] to bypass cache freshness
@@ -247,7 +243,7 @@ class TimetableBloc
}
void _writeWeekToCache(DateTime weekStart, TimetableGetWeekResponse week) {
final key = _weekKeyFormat.format(weekStart);
final key = weekStart.weekKey();
add(
Emit((s) {
final updated = Map<String, TimetableGetWeekResponse>.of(s.weekCache);
+5 -1
View File
@@ -19,7 +19,11 @@ class PostLoginSplash extends StatefulWidget {
try {
_darkComposition ??= await AssetLottie(_darkAsset).load();
_lightComposition ??= await AssetLottie(_lightAsset).load();
} catch (_) {}
} catch (e) {
// Precache is a best-effort warm-up; the splash falls back to loading the
// composition on demand. Log so a broken asset is at least diagnosable.
debugPrint('PostLoginSplash.precache failed: $e');
}
}
final VoidCallback onComplete;
+5
View File
@@ -115,6 +115,11 @@ void main() {
final end = dt.add(const Duration(minutes: 45));
expect(dt.timeRangeTo(end), '09:07 - 09:52');
});
test('weekKey renders a zero-padded yyyyMMdd key', () {
expect(dt.weekKey(), '20260508');
expect(DateTime(2026, 12, 31).weekKey(), '20261231');
});
});
group('formatDateRelativeShort', () {