Skip to content

Commit 903e489

Browse files
committed
改进DateTime支持写入null
1 parent 6ab5509 commit 903e489

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/model/type/DateTime.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function data($time, $format)
3333
} elseif (strpos('.', $time)) {
3434
$time = \DateTime::createFromFormat('Y-m-d H:i:s.u', $time);
3535
} else {
36-
$time = (new \DateTime($time));
36+
$time = $time ? (new \DateTime($time)) : null;
3737
}
3838
$this->format = $format;
3939
}
@@ -52,6 +52,10 @@ public function format(string $format = '')
5252
return $this->data->__toString();
5353
}
5454

55+
if (is_null($this->data)) {
56+
return null;
57+
}
58+
5559
return $this->data->format($format ?: $this->format);
5660
}
5761

0 commit comments

Comments
 (0)