Completed
Push — master ( 6ffc3f...4609e3 )
by Antonio
51:14 queued 46:44
created

iCalFormat::unixToiCal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
/*
4
 * This file is part of the 2amigos/yii2-qrcode-component project.
5
 *
6
 * (c) 2amigOS! <http://2amigos.us/>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace Da\QrCode\Format;
13
14
/**
15
 * iCal creates a valid iCal format string
16
 *
17
 * @author Antonio Ramirez <[email protected]>
18
 * @link http://www.ramirezcobos.com/
19
 * @link http://www.2amigos.us/
20
 * @package Da\QrCode\Format
21
 */
22
class iCalFormat extends AbstractFormat
23
{
24
    /**
25
     * @var string the event summary
26
     */
27
    public $summary;
28
    /**
29
     * @var integer the unix timestamp of the start date of the event
30
     */
31
    public $startTimestamp;
32
    /**
33
     * @var integer the unix timestamp of the end date of the event
34
     */
35
    public $endTimestamp;
36
37
    /**
38
     * @inheritdoc
39
     */
40
    public function getText()
41
    {
42
        $data = [];
43
        $data[] = "BEGIN:VEVENT";
44
        $data[] = "SUMMARY:{$this->summary}";
45
        $data[] = "DTSTART:{$this->unixToiCal($this->startTimestamp)}";
46
        $data[] = "DTEND:{$this->unixToiCal($this->endTimestamp)}";
47
        $data[] = "END:VEVENT";
48
49
        return implode("\n", $data);
50
    }
51
52
    /**
53
     * Converts a unix timestamp to iCal format. Timezones are assumed to be included into the timestamp.
54
     *
55
     * @param int $value the unix timestamp to convert
56
     *
57
     * @return bool|string the formatted date
58
     */
59
    protected function unixToiCal($value)
60
    {
61
        return date("Ymd\THis\Z", $value);
62
    }
63
}
64