summaryrefslogtreecommitdiffstats
path: root/vendor/ipl/web/src/Widget/TimeSince.php
blob: 308e358002aaf5a827dccd7bd37dc342b447ba4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php

namespace ipl\Web\Widget;

use Icinga\Date\DateFormatter;
use ipl\Html\BaseHtmlElement;

class TimeSince extends BaseHtmlElement
{
    /** @var int */
    protected $since;

    protected $tag = 'time';

    protected $defaultAttributes = ['class' => 'time-since'];

    public function __construct($since)
    {
        $this->since = (int) $since;
    }

    protected function assemble()
    {
        $dateTime = DateFormatter::formatDateTime($this->since);

        $this->addAttributes([
            'datetime' => $dateTime,
            'title'    => $dateTime
        ]);

        $this->add(DateFormatter::timeSince($this->since));
    }
}