/** * get the time spent on the site as a DateInterval * returns null if unable to calculate the interval. * @param Mage_Log_Model_Visitor * @return DateInterval */ protected function _getTimeSpentOnSite(Mage_Log_Model_Visitor $visitorLog = null) { if ($visitorLog) { $start = date_create_from_format(self::MAGE_DATETIME_FORMAT, $visitorLog->getFirstVisitAt()) ?: null; $end = date_create_from_format(self::MAGE_DATETIME_FORMAT, $visitorLog->getLastVisitAt()) ?: null; if ($start && $end && $start < $end) { $timeSpentOnSite = $end->diff($start); } } return isset($timeSpentOnSite) ? $timeSpentOnSite : null; }