Conditions | 7 |
Paths | 8 |
Total Lines | 32 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
9 | protected function validateCastValue($val) |
||
10 | { |
||
11 | switch ($this->format()) { |
||
12 | case 'default': |
||
|
|||
13 | try { |
||
14 | list($year, $month, $day) = explode('-', $val); |
||
15 | |||
16 | return Carbon::create($year, $month, $day, 0, 0, 0, 'UTC'); |
||
17 | } catch (\Exception $e) { |
||
18 | throw $this->getValidationException($e->getMessage(), $val); |
||
19 | } |
||
20 | case 'any': |
||
21 | try { |
||
22 | $date = new Carbon($val); |
||
23 | $date->setTime(0, 0, 0); |
||
24 | |||
25 | return $date; |
||
26 | } catch (\Exception $e) { |
||
27 | throw $this->getValidationException($e->getMessage(), $val); |
||
28 | } |
||
29 | default: |
||
30 | $date = strptime($val, $this->format()); |
||
31 | if ($date === false || $date['unparsed'] != '') { |
||
32 | throw $this->getValidationException("couldn't parse date/time according to given strptime format '{$this->format()}''", $val); |
||
33 | } else { |
||
34 | return Carbon::create( |
||
35 | (int) $date['tm_year'] + 1900, (int) $date['tm_mon'] + 1, (int) $date['tm_mday'], |
||
36 | 0, 0, 0 |
||
37 | ); |
||
38 | } |
||
39 | } |
||
40 | } |
||
41 | |||
47 |