Passed
Push — master ( 9b4e67...25f483 )
by Caen
02:57 queued 12s
created

DateString   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A __toString() 0 3 1
1
<?php
2
3
namespace Hyde\Framework\Models;
4
5
use DateTime;
6
7
/**
8
 * Parse a date string and create normalized formats.
9
 *
10
 * @see \Hyde\Framework\Testing\Unit\DateStringTest
11
 */
12
class DateString implements \Stringable
13
{
14
    /** The original date string. */
15
    public string $string;
16
17
    /** The parsed date object. */
18
    public DateTime $dateTimeObject;
19
20
    /** The machine-readable datetime string. */
21
    public string $datetime;
22
23
    /** The human-readable sentence string. */
24
    public string $sentence;
25
26
    /** Shorter version of the sentence string. */
27
    public string $short;
28
29
    public function __construct(string $string)
30
    {
31
        $this->string = $string;
32
        $this->dateTimeObject = new DateTime($this->string);
33
34
        $this->datetime = $this->dateTimeObject->format('c');
35
        $this->sentence = $this->dateTimeObject->format('l M jS, Y, \a\t g:ia');
36
        $this->short = $this->dateTimeObject->format('M jS, Y');
37
    }
38
39
    public function __toString(): string
40
    {
41
        return $this->short;
42
    }
43
}
44