本文整理汇总了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);
}