DateTrait::setOutputTimezone()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Copyright (c) 2017–2019 Ryan Parman <http://ryanparman.com>.
4
 * Copyright (c) 2017–2019 Contributors.
5
 *
6
 * http://opensource.org/licenses/Apache2.0
7
 */
8
9
declare(strict_types=1);
10
11
namespace SimplePie\Mixin;
12
13
/**
14
 * Shared code for working with elements which manage dates.
15
 */
16
trait DateTrait
17
{
18
    /**
19
     * The format that should be used when determining how to parse a date from a date string.
20
     *
21
     * @var string
22
     */
23
    protected $createFromFormat;
24
25
    /**
26
     * The preferred timezone to use for date output.
27
     *
28
     * @var string
29
     */
30
    protected $outputTimezone;
31
32
    /**
33
     * Allows the user to help the date parser by providing the format of the datestamp in the feed.
34
     *
35
     * This will be passed into `DateTime::createFromFormat()` at parse-time.
36
     *
37
     * @param string $createFromFormat The format of the datestamp in the feed.
38
     *
39
     * @see http://php.net/manual/en/datetime.createfromformat.php
40
     */
41 1
    public function setDateFormat(string $createFromFormat): self
42
    {
43 1
        $this->createFromFormat = $createFromFormat;
44
45 1
        return $this;
46
    }
47
48
    /**
49
     * Set the preferred output timezone.
50
     *
51
     * This calculation is performed on a _best-effort_ basis and is not guaranteed. Factors which may affect the
52
     * calculation include:
53
     *
54
     * * the version of glibc/musl that your OS relies on
55
     * * the freshness of the timestamp data your OS relies on
56
     * * the format of the datestamp inside of the feed and PHP's ability to parse it
57
     *
58
     * @param string $timezone The timezone identifier to use. Must be compatible with `DateTimeZone`. The default
59
     *                         value is `UTC`.
60
     */
61 1
    public function setOutputTimezone(string $timezone = 'UTC'): self
62
    {
63 1
        $this->outputTimezone = $timezone;
64
65 1
        return $this;
66
    }
67
}
68