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

DateTimeFormatter::toDateTimeImmutable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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