Completed
Pull Request — master (#3)
by
unknown
03:46
created

DateTimeFormatter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 23
wmc 2
lcom 0
cbo 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toDateTime() 0 4 1
A toDateTimeImmutable() 0 4 1
1
<?php
2
3
namespace Hborras\TwitterAdsSDK\DateTime;
4
5
/**
6
 * A collection of helper functions for string->date conversion
7
 *
8
 * @since 2016-06-24
9
 */
10
trait DateTimeFormatter
11
{
12
    /**
13
     * Returns a DateTime object from a date string.
14
     *
15
     * @param string
16
     * @return DateTime
17
     */
18
    public function toDateTime($datestr)
19
    {
20
        return (new \DateTime($datestr))->setTimeZone(new \DateTimeZone('UTC'));
21
    }
22
    /**
23
     * Returns an ImmutableDateTime object from a date string.
24
     *
25
     * @param string
26
     * @return DateTimeImmutable
27
     */
28
    public function toDateTimeImmutable($datestr)
29
    {
30
        return (new \DateTimeImmutable($datestr))->setTimeZone(new \DateTimeZone('UTC'));
31
    }
32
}
33