Пример #1
0
 /**
  * Calculate $creation and $last_update dates at beginning of each Dao::write() call
  *
  * @return string[] properties added to Only
  */
 public function beforeWriteDateLogged()
 {
     if (!isset($this->creation) || $this->creation->isEmpty()) {
         $this->creation = new Date_Time();
         $only[] = 'creation';
     }
     $this->last_update = new Date_Time();
     $only[] = 'last_update';
     return $only;
 }
Пример #2
0
 /**
  * @param $source Reflection_Source
  */
 public function onCompileSource(Reflection_Source $source)
 {
     Dao::begin();
     foreach ($source->getClasses() as $class) {
         /** @var $log Compiler_Log */
         $log = Builder::create(Compiler_Log::class);
         $log->class_name = $class->getName();
         $log->date_time = Date_Time::now();
         Dao::write($log);
         $this->log_flag = true;
     }
     Dao::commit();
 }
Пример #3
0
 /**
  * Takes an ISO date and make it locale
  *
  * @param $date string ie '2001-12-25' '2001-12-25 12:20:00' '2001-12-25 12:20:16'
  * @return string '25/12/2011' '25/12/2001 12:20' '25/12/2001 12:20:16'
  */
 public function toLocale($date)
 {
     // in case of $date being an object, ie Date_Time
     $date = strval($date);
     if (empty($date) || $date <= Date_Time::min()) {
         return '';
     }
     if (strlen($date) == 10) {
         return DateTime::createFromFormat('Y-m-d', $date)->format($this->format);
     } else {
         list($date, $time) = strpos($date, SP) ? explode(SP, $date) : [$date, ''];
         if (strlen($time) == 8 && substr($time, -3) == ':00') {
             substr($time, 0, 5);
         }
         $result = DateTime::createFromFormat('Y-m-d', $date)->format($this->format) . SP . $time;
         if (substr($result, -9) == ' 00:00:00') {
             $result = substr($result, 0, -9);
         } elseif (substr($result, -3) == ':00') {
             $result = substr($result, 0, -3);
         }
         return $result;
     }
 }
Пример #4
0
 /**
  * Register this for any Date_Time property using '@link DateTime' annotation
  *
  * @param $stored Date_Time|string
  * @return Date_Time
  */
 public static function getDateTime(&$stored)
 {
     if (is_string($stored)) {
         $stored = Date_Time::fromISO($stored);
     }
     return $stored;
 }