@davoodmehraban89 / LifeMate / commits / 336bed3
Fork 0

LifeMate — Personal, Family & Learning Companion

fix(reports): include today planned work through Tehran midnight

Codex committed Oct 8, 2026 at 16:33 UTC 336bed3673182deb129e6b201b84441265fb9396
2 files changed +61 -1
apps/lifemate/lib/dashboard_ui.dart
+5 -1
@@ -135,7 +135,11 @@ class _LearningReportPageState extends State<LearningReportPage>
135 if (busy) return;
136 setState(() => busy = true);
137 try {
138 - final to = DateTime.now().toUtc();
138 + final tehranNow =
139 + DateTime.now().toUtc().add(const Duration(hours: 3, minutes: 30));
140 + final to =
141 + DateTime.utc(tehranNow.year, tehranNow.month, tehranNow.day + 1)
142 + .subtract(const Duration(hours: 3, minutes: 30));
143 final result = await widget.api.getLearningReport(
144 widget.familyId, widget.childId,
145 from: to.subtract(Duration(days: days)), to: to);
apps/lifemate/test/study_ui_test.dart
+56
@@ -9,6 +9,7 @@ import 'package:lifemate/session_store.dart';
9 import 'package:lifemate/study_coordinator.dart';
10 import 'package:lifemate/study_ui.dart';
11 import 'package:lifemate/dashboard_ui.dart';
12 +import 'package:lifemate/phase3_ui.dart' show shortDate;
13 import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart';
14 import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
15
@@ -239,4 +240,59 @@ void main() {
240 api.close();
241 });
242 }
243 +
244 + testWidgets('weekly and monthly reports include the rest of today in Tehran',
245 + (tester) async {
246 + final now = DateTime.now().toUtc();
247 + final tehran = now.add(const Duration(hours: 3, minutes: 30));
248 + final dayEnd = DateTime.utc(tehran.year, tehran.month, tehran.day + 1)
249 + .subtract(const Duration(hours: 3, minutes: 30));
250 + final laterToday = now.add(dayEnd.difference(now) ~/ 2);
251 + final windows = <Map<String, DateTime>>[];
252 + final api = apiFor((request) async {
253 + final from = DateTime.parse(request.url.queryParameters['from']!);
254 + final to = DateTime.parse(request.url.queryParameters['to']!);
255 + windows.add({'from': from, 'to': to});
256 + final included = !laterToday.isBefore(from) && laterToday.isBefore(to);
257 + return jsonResponse({
258 + 'metrics': {
259 + 'plannedDurationSeconds': 1800,
260 + 'plannedInRangeDurationSeconds': included ? 1800 : 0,
261 + 'recordedDurationSeconds': 1500
262 + },
263 + 'items': [
264 + {
265 + 'id': 'today-plan',
266 + 'title': 'ریاضی امروز',
267 + 'kind': 'assignment',
268 + 'dueAt': laterToday.toIso8601String(),
269 + 'plannedDurationSeconds': 1800,
270 + }
271 + ],
272 + 'daily': [],
273 + 'subjects': [],
274 + 'asOf': now.toIso8601String(),
275 + });
276 + });
277 + await tester.pumpWidget(MaterialApp(
278 + home: LearningReportPage(
279 + api: api,
280 + familyId: 'family',
281 + childId: 'child',
282 + childName: 'فرزند')));
283 + await tester.pumpAndSettle();
284 + expect(windows.single['to'], dayEnd);
285 + expect(windows.single['from'], dayEnd.subtract(const Duration(days: 7)));
286 + expect(find.text('زمان برنامه‌ریزی‌شده: 30 دقیقه'), findsOneWidget);
287 + expect(find.text('زمان ثبت‌شده: 25 دقیقه'), findsOneWidget);
288 + expect(
289 + find.textContaining('دریافت سرور: ${shortDate(now)}'), findsOneWidget);
290 + await tester.tap(find.text('ماهانه'));
291 + await tester.pumpAndSettle();
292 + expect(windows.last['to'], dayEnd);
293 + expect(windows.last['from'], dayEnd.subtract(const Duration(days: 30)));
294 + expect(find.text('زمان برنامه‌ریزی‌شده: 30 دقیقه'), findsOneWidget);
295 + await tester.pumpWidget(const SizedBox());
296 + api.close();
297 + });
298 }