本文整理匯總了PHP中Illuminate\Database\Eloquent\Model::asDateTime方法的典型用法代碼示例。如果您正苦於以下問題:PHP Model::asDateTime方法的具體用法?PHP Model::asDateTime怎麽用?PHP Model::asDateTime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Illuminate\Database\Eloquent\Model
的用法示例。
在下文中一共展示了Model::asDateTime方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: asDateTime
/**
* @doc inherit
*/
protected function asDateTime($value)
{
if (in_array($value, ['0000-00-00 00:00:00', '0000-00-00'])) {
return null;
}
return parent::asDateTime($value);
}
示例2: asDateTime
protected function asDateTime($value)
{
if (starts_with($value, '0000')) {
return 'None';
}
return parent::asDateTime($value);
}
示例3: fromDateTime
/**
* Retain DateTime format for storage.
*
* @param \DateTime $value
*
* @return string
*/
public function fromDateTime($value)
{
if ($value instanceof DateTime) {
return $value;
}
return parent::asDateTime($value);
}
示例4: asDateTime
/**
* Return a timestamp as DateTime object.
*
* @inheritdoc
*/
protected function asDateTime($value)
{
if (0 === $value || null === $value || '0000-00-00 00:00:00' === $value) {
return null;
}
// catch standard datetime format
if (is_string($value) && preg_match('/^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$/', $value)) {
$value = Carbon::createFromFormat('Y-m-d H:i:s', $value);
}
return parent::asDateTime($value);
}
示例5: asDateTime
/**
* Return a timestamp as DateTime object.
*
* @param mixed $value
* @return DateTime
*/
protected function asDateTime($value)
{
// Convert MongoDate instances.
if ($value instanceof MongoDate) {
return Carbon::createFromTimestamp($value->sec);
}
return parent::asDateTime($value);
}
示例6: asDateTime
/**
* Handle case where the value might be from Carbon::toArray.
* @param mixed $value
* @return Carbon|static
*/
protected function asDateTime($value)
{
if ($value instanceof Carbon) {
return $value;
}
if ($value instanceof \DateTime) {
return Carbon::instance($value);
}
if (is_array($value) && isset($value['date'])) {
return Carbon::parse($value['date'], $value['timezone']);
}
try {
return Carbon::createFromFormat(Carbon::ISO8601, $value);
//try decode ISO8601 date
} catch (\InvalidArgumentException $e) {
return parent::asDateTime($value);
}
}
示例7: asDateTime
/**
* Return a timestamp as \Carbon\Carbon object.
*
* @param mixed $value
*
* @return \Carbon\Carbon
*/
protected function asDateTime($value)
{
// Convert MongoDate instances.
if ($value instanceof \Carbon\Carbon) {
return Carbon::now();
}
return parent::asDateTime($value);
}
示例8: asDateTime
/**
* Return a timestamp as DateTime object.
*
* @param mixed $value
* @return DateTime
*/
protected function asDateTime($value)
{
// Convert UTCDateTime instances.
if ($value instanceof UTCDateTime) {
return Carbon::createFromTimestamp($value->toDateTime()->getTimestamp());
}
return parent::asDateTime($value);
}
示例9: asDateTime
/**
* Return a timestamp as DateTime object.
*
* @inheritdoc
*/
protected function asDateTime($value)
{
if (0 === $value || null === $value) {
return null;
}
return parent::asDateTime($value);
}
示例10: asDateTime
/**
* Return a timestamp as DateTime object.
*
* @param mixed $value
* @return DateTime
*/
protected function asDateTime($value)
{
// Convert UTCDateTime instances.
if ($value instanceof UTCDateTime) {
return new Carbon($value->toDateTime()->format($this->getDateFormat()));
}
return parent::asDateTime($value);
}
示例11: asDateTime
/**
* Return a timestamp as DateTime object.
*
* @param mixed $value
* @return DateTime
*/
protected function asDateTime($value)
{
if ($value instanceof \stdClass) {
return Carbon::createFromTimestamp((new \DateTime($value->date))->getTimestamp());
}
return parent::asDateTime($value);
}
示例12: asDateTime
/**
* Return a timestamp as DateTime object.
*
* @param mixed $value Mixed Value
* @return \Carbon\Carbon
*/
public function asDateTime($value)
{
$value = asDateTime($value);
if (empty($value)) {
return $value;
}
return parent::asDateTime($value);
}
示例13: asDateTime
/**
* Return a timestamp as DateTime object.
*
* @param mixed $value
* @return DateTime
*/
protected function asDateTime($value)
{
// Convert MongoDate instances.
if ($value instanceof \MongoDB\BSON\UTCDateTime) {
return $value->toDateTime();
}
return parent::asDateTime($value);
}