Test Failed
Branch develop (09cda0)
by Samson
03:06
created

FromJdnConverter::setDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 8
rs 9.4285
c 1
b 0
f 1
1
<?php
2
3
namespace Andegna\Converter;
4
5
use Andegna\Exception\InvalidDateException;
6
7
/**
8
 * FromJdnConverter
9
 *
10
 * @package Andegna\Converter
11
 */
12
class FromJdnConverter extends Converter
13
{
14
    /**
15
     * FromJdnConverter constructor.
16
     *
17
     * @param $jdn int
18
     *
19
     * @throws \Andegna\Exception\InvalidDateException
20
     */
21
    public function __construct($jdn)
22
    {
23
        $this->set($jdn);
24
    }
25
26
    /**
27
     * @param $jdn
28
     *
29
     * @return $this
30
     * @throws \Andegna\Exception\InvalidDateException
31
     */
32
    public function set($jdn)
33
    {
34
        if (!$this->isValidInteger($jdn)) {
35
            throw new InvalidDateException();
36
        }
37
38
        $this->jdn = $jdn;
39
40
        $date = static::process($jdn);
41
42
        return $this->setDate($date);
43
    }
44
45
    protected static function process($jdn)
46
    {
47
        $r = (($jdn - 1723856) % 1461);
48
        $n = ($r % 365) + 365 * (int)($r / 1460);
49
50
        $year = 4 * (int)(($jdn - 1723856) / 1461) +
51
            (int)($r / 365) - (int)($r / 1460);
52
        $month = (int)($n / 30) + 1;
53
        $day = ($n % 30) + 1;
54
55
        return compact('day', 'month', 'year');
56
    }
57
58
    protected function setDate($date)
59
    {
60
        $this->day = $date['day'];
61
        $this->month = $date['month'];
62
        $this->year = $date['year'];
63
64
        return $this;
65
    }
66
}
67