DateHelper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 4
eloc 15
c 1
b 1
f 0
dl 0
loc 28
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A convertToLocal() 0 12 2
A convertToUTC() 0 12 2
1
<?php
2
3
namespace Gameap\Helpers;
4
5
use Carbon\Carbon;
6
use Carbon\CarbonImmutable;
7
8
class DateHelper
9
{
10
    public static function convertToLocal(?Carbon $date): ?CarbonImmutable
11
    {
12
        if ($date === null) {
13
            return null;
14
        }
15
16
        $convertedDate = CarbonImmutable::createFromFormat(
17
            Carbon::DEFAULT_TO_STRING_FORMAT,
18
            $date->toDateTimeString(),
19
            'UTC'
20
        );
21
        return $convertedDate->setTimezone(config('timezone'));
22
    }
23
24
    public static function convertToUTC(?Carbon $date): ?CarbonImmutable
25
    {
26
        if ($date === null) {
27
            return null;
28
        }
29
30
        $convertedDate = CarbonImmutable::createFromFormat(
31
            Carbon::DEFAULT_TO_STRING_FORMAT,
32
            $date->toDateTimeString(),
33
            config('timezone')
34
        );
35
        return $convertedDate->setTimezone('UTC');
36
    }
37
}
38