Total Complexity | 11 |
Total Lines | 74 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
14 | trait GeniusHelper |
||
15 | { |
||
16 | /** |
||
17 | * @param $value |
||
18 | * @return float|int|null |
||
19 | */ |
||
20 | public function dateToEpoch($value) |
||
21 | { |
||
22 | if ($value === null) { |
||
23 | return null; |
||
24 | } |
||
25 | return Carbon::parse($value)->timestamp * 1000; |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * @param $value |
||
30 | * @return float|int|null |
||
31 | */ |
||
32 | public function hourToEpoch($value) |
||
33 | { |
||
34 | if ($value === null) { |
||
35 | return null; |
||
36 | } |
||
37 | $time = Carbon::parse($value); |
||
38 | $hour = $time->format('H'); |
||
39 | $minutes = $time->format('i'); |
||
40 | $seconds = $time->format('s'); |
||
41 | return ($hour * 3600 + $minutes * 60 * $seconds) * 1000; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * @param $value |
||
46 | * @return null|string |
||
47 | */ |
||
48 | public function epochToHour($value) |
||
49 | { |
||
50 | if ($value === null) { |
||
51 | return null; |
||
52 | } |
||
53 | return Carbon::createFromTimeStampUTC($value / 1000)->toTimeString(); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * @param $value |
||
58 | * @return null|string |
||
59 | */ |
||
60 | public function epochToDate($value) |
||
61 | { |
||
62 | if ($value === null) { |
||
63 | return null; |
||
64 | } |
||
65 | return Carbon::createFromTimeStampUTC($value / 1000)->toDateString(); |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * @param $value |
||
70 | * @return null|string |
||
71 | */ |
||
72 | public function toDateFormat($value) |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * @param $value |
||
79 | * @param $format |
||
80 | * @return null|string |
||
81 | */ |
||
82 | public function epochToDateByDateFormat($value, $format) |
||
88 | } |
||
89 | } |
||
90 |