/**
  * Validate date params
  *
  * @param array  $params
  * @param string $reportType
  * @param int    $daysLimit  (optional)
  */
 protected function _validateReportDates(array &$params, $reportType, $daysLimit = null)
 {
     // Date format (YYYY-MM or YYYY-MM-DD)
     if (ReportModel::isMonthly($reportType)) {
         $format = 'Y-m';
     } else {
         if (ReportModel::isDaily($reportType)) {
             $format = 'Y-m-d';
         }
     }
     foreach (array('date', 'start', 'end') as $date) {
         if (isset($params[$date]) && !\DateTime::createFromFormat($format, $params[$date])) {
             throw new InvalidArgumentException("Invalid parameter value: {$date}. Supported values are using {$format} format");
         }
     }
     // BillingCycleStartDay for EXPENSE_DETAIL_MONTHLY REPORTS
     if ($reportType === ReportModel::EXPENSE_DETAIL_MONTHLY && isset($params['billingcyclestartday'])) {
         $billingCycleStartDay = $params['date'] . '-' . $params['billingcyclestartday'];
         if (!\DateTime::createFromFormat('Y-m-d', $billingCycleStartDay)) {
             throw new InvalidArgumentException("Invalid parameter value: {$date}. Supported values are using {$format} format");
         }
         $params['datebillingcyclestart'] = $billingCycleStartDay;
     }
     // Date interval (start < end)
     if (isset($params['start']) && isset($params['end'])) {
         $d1 = new \DateTime($params['start']);
         $d2 = new \DateTime($params['end']);
         $interval = $d1->diff($d2);
         if ($interval->invert) {
             throw new InvalidArgumentException('Invalid parameter value: end. Supported values are greater than start');
         }
         if ($daysLimit && $interval->days > $daysLimit) {
             throw new InvalidArgumentException("Invalid parameter value: end. Supported values are periods between 1 and {$daysLimit} days");
         }
     }
 }
 public function testIsDailyReturnsTrueIfReportTypeContainsDailyString()
 {
     $this->assertTrue(ReportModel::isDaily('expense_detail_daily'));
 }