Passed
Pull Request — master (#38)
by Ryan
25:32 queued 10:46
created

DateTrait::setOutputTimezone()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright (c) 2017–2018 Ryan Parman <http://ryanparman.com>.
4
 * Copyright (c) 2017–2018 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
     * @return self
40
     *
41
     * @see http://php.net/manual/en/datetime.createfromformat.php
42
     */
43
    public function setDateFormat(string $createFromFormat): self
44
    {
45
        $this->createFromFormat = $createFromFormat;
46
47
        return $this;
48
    }
49
50
    /**
51
     * Set the preferred output timezone.
52
     *
53
     * This calculation is performed on a _best-effort_ basis and is not guaranteed. Factors which may affect the
54
     * calculation include:
55
     *
56
     * * the version of glibc/musl that your OS relies on
57
     * * the freshness of the timestamp data your OS relies on
58
     * * the format of the datestamp inside of the feed and PHP's ability to parse it
59
     *
60
     * @param string $timezone The timezone identifier to use. Must be compatible with `DateTimeZone`. The default
61
     *                         value is `UTC`.
62
     *
63
     * @return self
64
     */
65
    public function setOutputTimezone(string $timezone = 'UTC'): self
66
    {
67
        $this->outputTimezone = $timezone;
68
69
        return $this;
70
    }
71
}
72