LCOV - code coverage report
Current view: top level - profile/util - date_util.dart (source / functions) Hit Total Coverage
Test: SWE574 - Fall2023 - Group1 - Mobile Test Coverage Lines: 18 18 100.0 %
Date: 2023-12-31 10:28:05 Functions: 0 0 -
Legend: Lines: hit not hit

          Line data    Source code
       1             : import 'package:memories_app/routes/home/model/story_model.dart';
       2             : 
       3           1 : String getFormattedDate(StoryModel story) {
       4           1 :   switch (story.dateType) {
       5           1 :     case 'year':
       6           3 :       return 'Year: ${story.year?.toString() ?? ''}';
       7           1 :     case 'decade':
       8           3 :       return 'Decade: ${story.decade?.toString() ?? ''}';
       9           1 :     case 'year_interval':
      10           5 :       return 'Start: ${story.startYear.toString()} \nEnd: ${story.endYear.toString()}';
      11           1 :     case 'normal_date':
      12           2 :       return formatDate(story.date) ?? '';
      13           1 :     case 'interval_date':
      14           5 :       return 'Start: ${formatDate(story.startDate)} \nEnd: ${formatDate(story.endDate)}';
      15             :     default:
      16             :       return '';
      17             :   }
      18             : }
      19             : 
      20           1 : String? formatDate(String? dateString) {
      21             :   if (dateString == null) {
      22             :     return null;
      23             :   }
      24             : 
      25             :   try {
      26           1 :     DateTime dateTime = DateTime.parse(dateString);
      27             : 
      28             :     bool isMidnight =
      29           6 :         dateTime.hour == 0 && dateTime.minute == 0 && dateTime.second == 0;
      30             : 
      31             :     String formattedDate = isMidnight
      32           5 :         ? dateTime.toLocal().toLocal().toString().split(' ')[0]
      33           3 :         : dateTime.toLocal().toLocal().toString();
      34             : 
      35             :     return formattedDate;
      36             :   } catch (e) {
      37             :     // ignore: avoid_print
      38           2 :     print('Error parsing date: $e');
      39             :     return null;
      40             :   }
      41             : }

Generated by: LCOV version 1.14