Completed
Branch master (c7b6b7)
by Pierre
19:40 queued 09:38
created

DocMarsTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 48
rs 10
1
<?php
2
3
namespace Popy\Calendar\Tests;
4
5
use DateTime;
6
use PHPUnit\Framework\TestCase;
7
use Popy\Calendar\Factory\ConfigurableFactory;
8
9
class DocMarsTest extends TestCase
10
{
11
    protected $factory;
12
    protected $mars;
13
14
    public function setUp()
15
    {
16
        $this->factory = new ConfigurableFactory();
17
        $this->mars = $this->factory->build([
18
            'era_start' => -3029702400,
19
            'era_start_year' => 1,
20
            'day_length' => 88775.244,
21
            'year_length' => 668.5991,
22
            'leap' => 'float',
23
            'month' => 'equal_length',
24
            'month_length' => 30,
25
            'week' => 'iso',
26
            'era_start_day_index' => 1,
27
            'week' => 'simple',
28
            'week_length' => 10,
29
        ]);
30
    }
31
32
    public function testMarsTime()
33
    {
34
        $this->assertEquals(
35
            $this->mars->format(
36
                new DateTime('1873-12-30 00:00:00'),
37
                "Y-m-d H:i:s"
38
            ),
39
            '0001-01-01 23:21:28'
40
        );
41
42
        /**
43
         * According to http://jtauber.github.io/mars-clock/, the MSD of this date
44
         * is 51232 sols after 1873-12-29 00:00:00 UTC, which is our era start.
45
         * That means the internal eraDayIndex should be 51232 aswell, year should be
46
         * ceil(51232/668.5921) = 77, and day index should be (51232 mod 668.5921) = 419
47
         */
48
        $this->assertEquals(
49
            $this->mars->format(
50
                new DateTime('2018-02-13 00:00:00 UTC'),
51
                "Y z"
52
            ),
53
            '0077 419'
54
        );
55
    }
56
}
57