Total Complexity | 8 |
Total Lines | 52 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | class Timezone |
||
8 | { |
||
9 | protected function formatTimezone(Carbon $date): string |
||
19 | } |
||
20 | |||
21 | public function toLocal(?Carbon $date): ?Carbon |
||
22 | { |
||
23 | if ($date === null) { |
||
24 | return null; |
||
25 | } |
||
26 | |||
27 | // TODO(sergotail): use geoip timezone suggestion for non-authorized users too |
||
28 | // (make it configurable) |
||
29 | $timezone = auth()->user()->getTimezone() ?? |
||
30 | config('timezone.default', null) ?? |
||
31 | config('app.timezone'); |
||
32 | |||
33 | return $date->copy()->setTimezone($timezone); |
||
34 | } |
||
35 | |||
36 | public function convertToLocal( |
||
37 | ?Carbon $date, |
||
38 | ?string $format = null, |
||
39 | bool $displayTimezone = false |
||
40 | ): string { |
||
41 | $date = $this->toLocal($date); |
||
42 | |||
43 | if ($date === null) { |
||
44 | return config('timezone.empty_date', 'Empty'); |
||
45 | } |
||
46 | |||
47 | $formatted = $date->format($format ?? config('timezone.format', 'jS F Y g:i:a')); |
||
48 | |||
49 | if ($displayTimezone) { |
||
50 | return $formatted . ' ' . $this->formatTimezone($date); |
||
51 | } |
||
52 | |||
53 | return $formatted; |
||
54 | } |
||
55 | |||
56 | public function convertFromLocal($date): Carbon |
||
59 | } |
||
60 | } |
||
61 |