Пример #1
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;
     }
 }