Exemplo n.º 1
0
 static function convertForDisplay($date, $separator = '-', $abbreviate = false)
 {
     if ($date === null) {
         return null;
     } else {
         if (!LsDate::validate($date)) {
             throw new Exception("Can't convert: invalid date");
         }
     }
     list($year, $month, $day) = explode('-', $date);
     if (intval($year) < 1930) {
         $abbreviate = false;
     }
     if (intval($year) > 0 && intval($month) > 0 && intval($day) > 0) {
         $ret = date('M j \'y', strtotime($date));
     } elseif (intval($year) > 0 && intval($month) > 0) {
         //the month needs to be incremented because strtotime interprets '2008-12-00' as '2008-11-31'
         $year = $month > 10 ? $year + 1 : $year;
         $month = ($month + 1) % 12;
         $ret = date('M \'y', strtotime(implode('-', array($year, $month, $day))));
     } elseif ($year) {
         if ($abbreviate) {
             $ret = '\'' . substr($year, 2, 2);
         } else {
             $ret = $year;
         }
     } else {
         $ret = null;
     }
     return $ret;
 }