/**
  * Convert a date passed as 'YYYY-MM-DD', SS_Datetime or year, month, day
  * to checkfront 'YYYYMMDD' format.
  *
  * @param string|null $dateOrYear
  * @param null $month
  * @param null $day
  *
  * @return bool|mixed|string
  * @throws Exception
  */
 public static function checkfront_date($dateOrYear, $month = null, $day = null)
 {
     $checkfrontFormat = CheckfrontModule::checkfront_date_format();
     if (empty($dateOrYear)) {
         return date($checkfrontFormat);
     } elseif ($dateOrYear instanceof SS_Datetime) {
         // build from SS_Datetime
         $result = $dateOrYear->Year() . $dateOrYear->Month() . $dateOrYear->Day();
     } elseif (is_int($dateOrYear)) {
         // year is an integer year
         if (func_num_args() === 1 && $dateOrYear > mktime(0, 0, 0, 1, 1, 1970)) {
             // $dateOrYear is probably a unix timestamp
             $result = date($checkfrontFormat, $dateOrYear);
         } elseif (func_num_args() === 3) {
             // $dateOrYear is year, and month and day supplied
             $result = date($checkfrontFormat, mktime(0, 0, 0, $month, $day, $dateOrYear));
         } else {
             throw new CheckfrontException("Need either 1 or 3 arguments when dataOrYear is an integer", CheckfrontException::TypeError);
         }
     } elseif (3 === explode($dateOrYear, '-')) {
         // probably formatted as YYYY-MM-DD
         $result = str_replace(array('-', '_'), '', $dateOrYear);
         if (!is_numeric($result)) {
             throw new CheckfrontException("Invalid date passed: '{$dateOrYear}'", CheckfrontException::TypeError);
         }
     } else {
         // this may be something that strtotime can use e.g. 'today' or '+2 month'?
         $unixTime = strtotime($dateOrYear);
         if ($unixTime === false) {
             throw new CheckfrontException("Invalid date passed: '{$dateOrYear}'", CheckfrontException::TypeError);
         }
         $result = date($checkfrontFormat, $unixTime);
     }
     return $result;
 }