| Total Complexity | 9 |
| Total Lines | 73 |
| Duplicated Lines | 0 % |
| Changes | 4 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 7 | class Timezone |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @param Carbon|null $date |
||
| 11 | * @param null $format |
||
|
|
|||
| 12 | * @param bool $format_timezone |
||
| 13 | * @return string |
||
| 14 | */ |
||
| 15 | public function convertToLocal(?Carbon $date, $format = null, $format_timezone = false): string |
||
| 16 | { |
||
| 17 | if (is_null($date)) { |
||
| 18 | return 'Empty'; |
||
| 19 | } |
||
| 20 | |||
| 21 | $timezone = (auth()->user()->timezone) ?? config('app.timezone'); |
||
| 22 | |||
| 23 | $date->setTimezone($timezone); |
||
| 24 | |||
| 25 | if (is_null($format)) { |
||
| 26 | return $date->format(config('timezone.format')); |
||
| 27 | } |
||
| 28 | |||
| 29 | $formatted_date_time = $date->format($format); |
||
| 30 | |||
| 31 | if ($format_timezone) { |
||
| 32 | return $formatted_date_time.' '.$this->formatTimezone($date); |
||
| 33 | } |
||
| 34 | |||
| 35 | return $formatted_date_time; |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @param Carbon|null $date |
||
| 40 | * @return string |
||
| 41 | */ |
||
| 42 | public function convertToLocalDiffForHumans(?Carbon $date): string |
||
| 43 | { |
||
| 44 | if (is_null($date)) { |
||
| 45 | return 'Empty'; |
||
| 46 | } |
||
| 47 | |||
| 48 | $timezone = (auth()->user()->timezone) ?? config('app.timezone'); |
||
| 49 | |||
| 50 | $date->setTimezone($timezone); |
||
| 51 | |||
| 52 | $diffTime = Carbon::parse($date)->diffForHumans(); |
||
| 53 | |||
| 54 | return $diffTime; |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @param $date |
||
| 59 | * @return Carbon |
||
| 60 | */ |
||
| 61 | public function convertFromLocal($date): Carbon |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @param Carbon $date |
||
| 68 | * @return string |
||
| 69 | */ |
||
| 70 | private function formatTimezone(Carbon $date): string |
||
| 80 | } |
||
| 81 | } |
||
| 82 |