Completed
Push — master ( b35b0f...acc097 )
by Greg
05:21
created

Date::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * /classes/DomainMOD/Date.php
4
 *
5
 * This file is part of DomainMOD, an open source domain and internet asset manager.
6
 * Copyright (c) 2010-2017 Greg Chetcuti <[email protected]>
7
 *
8
 * Project: http://domainmod.org   Author: http://chetcuti.com
9
 *
10
 * DomainMOD is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
11
 * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
12
 * version.
13
 *
14
 * DomainMOD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
15
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License along with DomainMOD. If not, see
18
 * http://www.gnu.org/licenses/.
19
 *
20
 */
21
//@formatter:off
22
namespace DomainMOD;
23
24
class Date
25
{
26
    public $time;
27
28
    public function __construct()
29
    {
30
        $this->time = new Time();
31
    }
32
33
    public function checkDateFormat($input_date)
34
    {
35
        if (preg_match('/^(\d{4})-(\d{2})-(\d{2})$/', $input_date, $output_date)) {
36
37
            return checkdate($output_date[2], $output_date[3], $output_date[1]);
38
39
        } else {
40
41
            return false;
42
43
        }
44
    }
45
46
    public function splitAndCheckRange($daterange)
47
    {
48
        $start_date = substr($daterange, 0, 10);
49
        $end_date = substr($daterange, -10, 10);
50
51
        if (!$this->checkDateFormat($start_date)) $start_date = $this->time->timeBasicMinusDays('14');
52
        if (!$this->checkDateFormat($end_date)) $end_date = $this->time->timeBasicPlusYears('11');
53
54
        return array($start_date, $end_date);
55
    }
56
57
} //@formatter:on
58