Completed
Push — master ( 0da900...d5ed8a )
by Oscar
01:30
created

Datetime::getDefaultValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types = 1);
3
4
namespace SimpleCrud\Fields;
5
6
class Datetime extends Field
7
{
8
    protected $format = 'Y-m-d H:i:s';
9
10
    public function format($value): ?\Datetime
11
    {
12
        if ($value instanceof \Datetime) {
13
            return $value;
14
        }
15
16
        return $value ? new \Datetime($value) : null;
17
    }
18
19
    protected function formatToDatabase($value): ?string
20
    {
21
        $value = $this->format($value);
22
23
        return empty($value) ? null : $value->format($this->format);
24
    }
25
}
26