Exemple #1
0
 /**
  * Returns the last modified time
  *
  * @param string $key
  *
  * @param bool   $asDateTimeObject (Optional) Return as DateTimeObject if true
  *
  * @return UNIX Timestamp or DateTimeObject
  */
 public function getTimeModified($key, $asDateTimeObject = false)
 {
     $time = $this->driver->getTimeModified($key);
     if ($asDateTimeObject) {
         $datetime = new DateTimeObject();
         return $datetime->setTimestamp($time);
     }
     return $time;
 }
Exemple #2
0
 /**
  * Create a DateTimeObject from the given $time and $format.
  *
  * @param string|int  $time Timestamp.
  * @param null|string $format Format in which the current timestamp is defined.
  *
  * @return DateTimeObject
  * @throws DateTimeObjectException
  */
 public static function createFromFormat($time, $format = null)
 {
     if (self::isNull($format)) {
         $format = self::$defaultFormat;
     }
     try {
         $date = \DateTime::createFromFormat($format, $time);
         if (!$date) {
             throw new DateTimeObjectException(DateTimeObjectException::MSG_UNABLE_TO_CREATE_FROM_FORMAT);
         }
     } catch (\Exception $e) {
         throw new DateTimeObjectException(DateTimeObjectException::MSG_UNABLE_TO_CREATE_FROM_FORMAT);
     }
     try {
         $dt = new DateTimeObject();
         $dt->setTimestamp($date->getTimestamp());
         $dt->setFormat($format);
     } catch (\Exception $e) {
         throw new DateTimeObjectException(DateTimeObjectException::MSG_UNABLE_TO_CREATE_FROM_FORMAT);
     }
     return $dt;
 }