Passed
Push — master ( 2d2309...cbe71d )
by Nikita
26:59 queued 05:24
created

DateHelper::convertToUTC()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 5
dl 0
loc 8
rs 10
c 1
b 1
f 0
cc 1
nc 1
nop 1
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
        $convertedDate = CarbonImmutable::createFromFormat(
13
            Carbon::DEFAULT_TO_STRING_FORMAT,
14
            $date->toDateTimeString(),
15
            'UTC'
16
        );
17
        return $convertedDate->setTimezone(config('timezone'));
18
    }
19
20
    public static function convertToUTC(Carbon $date): CarbonImmutable
21
    {
22
        $convertedDate = CarbonImmutable::createFromFormat(
23
            Carbon::DEFAULT_TO_STRING_FORMAT,
24
            $date->toDateTimeString(),
25
            config('timezone')
26
        );
27
        return $convertedDate->setTimezone('UTC');
28
    }
29
}
30