예제 #1
0
 public function toPrimitiveType($value)
 {
     $value2 = parent::toPrimitiveType($value);
     if (is_null($value2) || $value2 instanceof DateTime) {
         return $value2;
     }
     if (is_string($value)) {
         return DateTime::createFromFormat($this->getOption('fromformat'), $value, $this->getDateTimeZone());
     } else {
         if (is_array($value)) {
             return DateTime::createFromFormat("Y-m-d", "{$value['year']}-{$value['mon']}-{$value['mday']}", $this->getDateTimeZone());
         }
     }
     throw new Exception("Invalid date.");
 }
 public function toPrimitiveType($value)
 {
     $value = parent::toPrimitiveType($value);
     if (is_null($value) || $value instanceof DateTime) {
         return $value;
     }
     if (is_string($value)) {
         if (substr_count($value, $this->getOption('timeseparator')) == 1) {
             $value .= $this->getOption('timeseparator') . '00';
         }
         return DateTime::createFromFormat($this->getOption('fromlongformat'), $value, $this->getDateTimeZone());
     } else {
         if (is_array($value)) {
             return DateTime::createFromFormat('Y-m-d H:i:s', sprintf('%d-%02d-%02d %02d:%02d:%02d', $value['year'], $value['mon'], $value['mday'], $value['hours'], $value['minutes'], $value['seconds']), $this->getDateTimeZone());
         }
     }
     throw new Exception('Invalid timestamp.');
 }