LCOV - code coverage report
Current view: top level - utils - date_helper.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 13 13 100.0 %
Date: 2022-10-19 14:19:28 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:alh_calendar/models/calendar_week.dart';
       2             : 
       3             : /// Collection of methods regarding the calculation of the dates.
       4             : class DateHelper {
       5             :   /// Checks if maximum month has been reached.
       6             :   ///
       7             :   /// Returns true if the year and month of [currentDateTime]
       8             :   /// is equal or higher then year and month of [maximumDateTime].
       9           2 :   static bool isMaximumMonthDateReached({
      10             :     required DateTime maximumDateTime,
      11             :     required DateTime currentDateTime,
      12             :   }) {
      13           6 :     return currentDateTime.year >= maximumDateTime.year &&
      14           6 :         currentDateTime.month >= maximumDateTime.month;
      15             :   }
      16             : 
      17             :   /// Checks if minimum month has been reached.
      18             :   ///
      19             :   /// Returns true if the year and month of [currentDateTime]
      20             :   /// is equal or lower then year and month of maximumDateTime.
      21           2 :   static bool isMinimumMonthDateReached({
      22             :     required DateTime minimumMonthDate,
      23             :     required DateTime currentDateTime,
      24             :   }) {
      25           6 :     return currentDateTime.year <= minimumMonthDate.year &&
      26           6 :         currentDateTime.month <= minimumMonthDate.month;
      27             :   }
      28             : 
      29             :   /// Checks if a given day is out of Range
      30             :   ///
      31             :   /// Out of Range means that the day does not lay between the
      32             :   /// [minimumDayDate] and maximumDayData. If maximumDayDate is null
      33             :   /// all days before the minimumDayDate are out of Range, if minimumDayDate
      34             :   /// is null all day beyond maximumDayDate are out of Range. If both are null
      35             :   /// there is no Range, so no day can be out of range.
      36           4 :   static bool isDayOutOfRange({
      37             :     required DateTime dayDateTime,
      38             :     required DateTime? minimumDayDate,
      39             :     required DateTime? maximumDayDate,
      40             :   }) {
      41             :     if (minimumDayDate != null && maximumDayDate != null) {
      42           4 :       return dayDateTime.isBefore(minimumDayDate) ||
      43           4 :           dayDateTime.isAfter(maximumDayDate);
      44             :     } else if (minimumDayDate != null) {
      45           1 :       return dayDateTime.isBefore(minimumDayDate);
      46             :     } else if (maximumDayDate != null) {
      47           1 :       return dayDateTime.isAfter(maximumDayDate);
      48             :     } else {
      49             :       return false;
      50             :     }
      51             :   }
      52             : 
      53             :   /// Checks if any day of [CalendarWeek] is in current month using isInCurrentMonth flag
      54             :   ///
      55             :   /// Required if the disableSixthRow is true, because if one day of
      56             :   /// the current month is in the sixth week, then the sixth row should NOT
      57             :   /// be disabled.
      58           2 :   static bool isDayOfCurrentMonthInLastRow({
      59             :     required CalendarWeek calendarWeek,
      60             :   }) {
      61           8 :     return calendarWeek.days.any((day) => day.isInCurrentMonth);
      62             :   }
      63             : }

Generated by: LCOV version 1.16