1 | <?php |
||
15 | class DateTime extends AbstractFormatterProvider |
||
16 | { |
||
17 | protected $carbon; |
||
18 | |||
19 | 12 | public function __construct(Carbon $carbon) |
|
23 | |||
24 | /** |
||
25 | * Format the datetime as a date |
||
26 | * |
||
27 | * @param mixed $value |
||
28 | * @param string $format |
||
29 | * @return string |
||
30 | */ |
||
31 | 3 | public function asDate($value, $format = 'Y-m-d') |
|
35 | |||
36 | /** |
||
37 | * Format the datetime as a date |
||
38 | * |
||
39 | * @param mixed $value |
||
40 | * @param string $format |
||
41 | * @return string |
||
42 | */ |
||
43 | 1 | public function asTime($value, $format = 'H:i:s') |
|
47 | |||
48 | /** |
||
49 | * Format the datetime as a date |
||
50 | * |
||
51 | * @param mixed $value |
||
52 | * @param string $format |
||
53 | * @return string |
||
54 | */ |
||
55 | 1 | public function asDateTime($value, $format = 'Y-m-d H:i:s') |
|
59 | |||
60 | /** |
||
61 | * Take in a number of seconds and display that as a human readable amount |
||
62 | * of time |
||
63 | * |
||
64 | * From: https://jonlabelle.com/snippets/view/php/convert-seconds-to-human-readable |
||
65 | * |
||
66 | * @param int $seconds |
||
67 | * @return string |
||
68 | * @todo allow units to be overridden (non-english..) |
||
69 | */ |
||
70 | 6 | public function asDurationHuman($seconds, $delimit = ', ') |
|
108 | |||
109 | /** |
||
110 | * Generate the output from the value |
||
111 | * |
||
112 | * @param mixed $value the datetime value |
||
113 | * @param string $format format string |
||
114 | * @return string |
||
115 | */ |
||
116 | 5 | private function output($value, $format) |
|
122 | |||
123 | /** |
||
124 | * Convert the datetime input into a instance of Carbon |
||
125 | * |
||
126 | * @param mixed $value the datetime value |
||
127 | * @return Carbon |
||
128 | */ |
||
129 | 5 | private function normaliseValue($value) |
|
138 | |||
139 | /** |
||
140 | * Get an instance of the carbon datetime handler |
||
141 | * |
||
142 | * @return Carbon |
||
143 | * @throws FormatterException if carbon isn't available |
||
144 | */ |
||
145 | 5 | private function getCarbon() |
|
149 | } |
||
150 |