format($this->_format); } /** * Convert strings into DateTime instances. * * @param string $value The value to convert. * @param Driver $driver The driver instance to convert with. * @return \Carbon\Carbon */ public function toPHP($value, Driver $driver) { if ($value === null) { return null; } list($value) = explode('.', $value); $class = static::$dateTimeClass; return $class::createFromFormat($this->_format, $value); } /** * Convert request data into a datetime object. * * @param mixed $value Request data * @return \Carbon\Carbon */ public function marshal($value) { if ($value instanceof \DateTime) { return $value; } $class = static::$dateTimeClass; try { if ($value === '' || $value === null || $value === false || $value === true) { return $value; } elseif (is_numeric($value)) { $date = new $class('@' . $value); } elseif (is_string($value)) { $date = new $class($value); } if (isset($date)) { return $date; } } catch (\Exception $e) { return $value; } $value += ['hour' => 0, 'minute' => 0, 'second' => 0]; $format = ''; if ( isset($value['year'], $value['month'], $value['day']) && (is_numeric($value['year']) & is_numeric($value['month']) && is_numeric($value['day'])) ) { $format .= sprintf('%d-%02d-%02d', $value['year'], $value['month'], $value['day']); } if (isset($value['meridian'])) { $value['hour'] = strtolower($value['meridian']) === 'am' ? $value['hour'] : $value['hour'] + 12; } $format .= sprintf('%02d:%02d:%02d', $value['hour'], $value['minute'], $value['second']); return new $class($format); } }