| Total Complexity | 9 |
| Total Lines | 73 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | 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 |
||
| 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 |
||
| 62 | { |
||
| 63 | return Carbon::parse($date, auth()->user()->timezone)->setTimezone('UTC'); |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @param Carbon $date |
||
| 68 | * @return string |
||
| 69 | */ |
||
| 70 | private function formatTimezone(Carbon $date) : string |
||
| 80 | } |
||
| 81 | } |
||
| 82 |