FlexiBee date to PHP DateTime conversion

@param string $flexidate 2017-05-26 or 2017-05-26+02:00

@return \DateTime | false
556284
public static function flexiDateToDateTime($flexidate)
    {
        return \DateTime::createFromFormat(strstr($flexidate, '+') ? self::$DateFormat.'O'
                    : self::$DateFormat, $flexidate)->setTime(0, 0);
    }
514008
function objectAttributeContent( $contentObjectAttribute )
    {
        $dateTime = new eZDateTime();
        $stamp = $contentObjectAttribute->attribute( 'data_int' );
        $dateTime->setTimeStamp( $stamp );
        return $dateTime;
    }
552774
public function mtime($key)
    {
        if ($object = $this->tryGetObject($key)) {
            return (new \DateTime($object->getLastModified()))->format('U');
        }

        return false;
    }
644164
private FileTime convertDateToFileTime(String strDate) {
        FileTime time = null;
        if (null != strDate) {
            Date date = null;
            try {
                date = DateUtil.convertToDate(strDate,
                                              DateUtil.DateFormat.LONG_FORMAT);
            } catch (ParseException e) {
                date = null;
            }

            if (null != date) {
                time = FileTime.fromMillis(date.getTime());
            }
        }
        return time;
    }
60205
public static function format($date = false, $format = 'Y-m-d H:i:s') {

        if($date) {

            $DateTime = new DateTime($date);
            return $DateTime->format($format);
        }

        return false;
    }
326561
public function parseDateTime($rawValue) {
		if (null === $rawValue) {
			return null;
		}
		
		try {
			$dateTime = DateUtils::createDateTimeFromFormat(MysqlDateTimeColumn::FORMAT_DATE_TIME, $rawValue);
			if ($dateTime->getTimestamp() === false) {
				throw new DateParseException('Invalid datetime raw value: ' . $rawValue);
			}
			return $dateTime;
		} catch (\n2n\util\DateParseException $e) {
			throw new \InvalidArgumentException($e->getMessage(), 0, $e);
		}
	}
716608
static function convert($input,$outputFormat=self::PHP) {
		if ($input===false) {
			$input=time();
		}

		if ($input instanceof \DateTime) {
			if ($outputFormat===self::INT) return $input->getTimestamp();
			if (is_string($outputFormat)) return date($outputFormat,$input->getTimestamp());
			if ($outputFormat===self::PHP) return $input;
			return null;
		}

		if (!is_numeric($input)) {
			$origInput = $input;
			$input=@strtotime($input);
			if ($input === false or $input === -1) {
				$input = str_replace(" ","",$origInput); // Helps with formats like 13. 5. 2013
				$input=@strtotime($input);
				if ($input === false or $input === -1) {
					throw new \InvalidArgumentException("Invalid input to Time::convert: $origInput");
				}
			}
		}

		if ($outputFormat===self::INT) return $input;
		if (is_string($outputFormat)) return date($outputFormat,$input);
		if ($outputFormat===self::PHP) {
			$d=new \DateTime();
			return $d->setTimestamp($input);
		}
		return null;
	}
1207552
public function toXML($validate = false){

        $returnValue = '';

        $qti = $this->toQTI();

        // render and clean the xml
        $dom = new DOMDocument('1.0', 'UTF-8');

        $domDocumentConfig = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiItem')->getConfig('XMLParser');

        if (is_array($domDocumentConfig) && !empty($domDocumentConfig)) {
            foreach ($domDocumentConfig as $param => $value) {
                if (property_exists($dom, $param)) {
                    $dom->$param = $value;
                }
            }
        } else {
            $dom->formatOutput = true;
            $dom->preserveWhiteSpace = false;
            $dom->validateOnParse = false;
        }

        if($dom->loadXML($qti)){
            $returnValue = $dom->saveXML();

            //in debug mode, systematically check if the save QTI is standard compliant
            if($validate){
                $parserValidator = new Parser($returnValue);
                $parserValidator->validate();
                if(!$parserValidator->isValid()){
                    common_Logger::w('Invalid QTI output: '.PHP_EOL.' '.$parserValidator->displayErrors());
                }
            }
        }else{
            $parserValidator = new Parser($qti);
            $parserValidator->validate();
            if(!$parserValidator->isValid()){
                throw new QtiModelException('Wrong QTI item output format');
            }
        }

        return (string) $returnValue;
    }
1075073
protected function formatDateTime(\DateTime $date = null, $format = null)
    {
        return $date && $format ?
            $date->format($format) :
            $date
        ;
    }
189146
static function mysqlToDateTime($mysqlDate = false)
    {
        return static::createFromFormat(static::$mysqlFormat, $mysqlDate)->format(Settings\DefaultDateSettings::$defaultDateTimeFromat);
    }
1276793
private DateTime parseToDate(String toDate) {
        // Default to now
        return parseDate(toDate, new DateTime().withZone(DateTimeZone.UTC), false);
    }
825633
public function readDate()
    {
        // get the unix time stamp. Not sure why ActionScript does not use
        // milliseconds
        $timestamp = floor($this->_stream->readDouble() / 1000);

        // The timezone offset is never returned to the server; it is always 0,
        // so read and ignore.
        $offset = $this->_stream->readInt();

        require_once 'Zend/Date.php';
        $date   = new Zend_Date($timestamp);
        return $date;
    }
1362653
public function convertBirthday($aData)
    {

        // preparing data to process
        $iYear = isset($aData['year']) ? ((int) $aData['year']) : false;
        $iMonth = isset($aData['month']) ? ((int) $aData['month']) : false;
        $iDay = isset($aData['day']) ? ((int) $aData['day']) : false;

        // leaving empty if not set
        if (!$iYear && !$iMonth && !$iDay) {
            return "";
        }

        // year
        if (!$iYear || $iYear < 1000 || $iYear > 9999) {
            $iYear = date('Y');
        }

        // month
        if (!$iMonth || $iMonth < 1 || $iMonth > 12) {
            $iMonth = 1;
        }

        // maximum number of days in month
        $iMaxDays = 31;
        switch ($iMonth) {
            case 2:
                if ($iMaxDays > 28) {
                    $iMaxDays = ($iYear % 4 == 0 && ($iYear % 100 != 0 || $iYear % 400 == 0)) ? 29 : 28;
                }
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                $iMaxDays = min(30, $iMaxDays);
                break;
        }

        // day
        if (!$iDay || $iDay < 1 || $iDay > $iMaxDays) {
            $iDay = 1;
        }

        // whole date
        return sprintf("%04d-%02d-%02d", $iYear, $iMonth, $iDay);
    }
1032761
public static function formatDate($firstDate, $secondDate = null, $returnAsArray = false)
    {
        if ($firstDate instanceof \DateTime) {
            $firstTimestamp = $firstDate->format('U');
        } elseif (is_int($firstDate)) {
            $firstTimestamp = strtotime($firstDate);
        } else {
            $firstTimestamp = strtotime($firstDate);
        }

        $secondTimestamp = null;
        if ($secondDate instanceof \DateTime) {
            $secondTimestamp = $secondDate->format('U');
        } elseif (is_int($secondDate)) {
            $secondTimestamp = strtotime($secondDate);
        } else {
            $secondTimestamp = strtotime($secondDate);
        }

        return self::formatTimestamp($firstTimestamp, $secondTimestamp, $returnAsArray);
    }
1218346
public function getFormattedDate($format, $startDate = true)
    {
        $date = $this->getEndDate();

        // Start date should be formatted?
        if ($startDate) {
            $date = $this->getStartDate();
        }

        // Unknown date or format is invalid?
        // Nothing to do
        if (null === $date || !Date::isValidDateFormat($format)) {
            return '';
        }

        return $date->format($format);
    }
53770
private function parseTimestamp($date, $locale = null) {
        // try time default formats
        foreach ($this->formats as $timeFormat) {
            // try date default formats
            foreach($this->formats as $dateFormat) {
                $dateFormater = \IntlDateFormatter::create($locale ?: \Locale::getDefault(), $dateFormat, $timeFormat, date_default_timezone_get());
                $timestamp = $dateFormater->parse($date);

                if ($dateFormater->getErrorCode() == 0) {
                    return $timestamp;
                }
            }
        }

        // try other custom formats
        $formats = array(
            'MMMM yyyy', // november 2011 - nov. 2011
        );
        foreach($formats as $format) {
            $dateFormater = \IntlDateFormatter::create($locale ?: \Locale::getDefault(), $this->formats['none'], $this->formats['none'],  date_default_timezone_get(), \IntlDateFormatter::GREGORIAN, $format);
            $timestamp = $dateFormater->parse($date);

            if ($dateFormater->getErrorCode() == 0) {
                return $timestamp;
            }
        }

        throw new \Exception('"'.$date.'" could not be converted to \DateTime');
    }
210865
public static function ruleDateTime()
    {
        return function ($input) {
            $date = null;
            try {
                $date = date_parse($input);
                return $date['warning_count'] === 0 && $date['error_count'] === 0;
            }
            catch(\Exception $e) {
                return false;
            }
        };
    }