Passed
Pull Request — master (#20)
by
unknown
01:59
created

TimeConverter   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 0
dl 0
loc 25
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A dateTimeConverter() 0 22 1
1
<?php
2
3
namespace PoLaKoSz\CoC_API\Helpers
4
{
5
    use \DateTime;
6
    use \DateTimeZone;
7
8
    class TimeConverter
9
    {
10
        public static function dateTimeConverter(string $date)
11
        {
12
            // 20180301T175029.000Z
13
14
            $date = substr( $date, 0, strpos( $date, '.000Z' ) );
15
16
            // 20180301T175029
17
18
            $date = str_replace( 'T', '', $date);
19
20
            // 20180301175029
21
22
            $year  = substr( $date, 0, 4 );
23
            $month = substr( $date, 4, 2 );
24
            $day   = substr( $date, 6, 2 );
25
26
            $hour  = substr( $date,  8, 2 );
27
            $min   = substr( $date, 10, 2 );
28
            $sec   = substr( $date, 12, 2 );
29
30
            return new DateTime($year . $month . $day . $hour . $min . $sec, new DateTimeZone('UTC'));
31
        }
32
    }
33
}