http://phing.info/

Source Code Coverage

Designed for use with PHPUnit2, Xdebug and Phing.

Methods: 6 LOC: 119 Statements: 15
Legend: executednot executeddead code
Source file Statements Methods Total coverage
Range.php 100.0% 100.0% 100.0%
 
1
<?php
2
/**
3
 * Xyster Framework
4
 *
5
 * This source file is subject to the new BSD license that is bundled
6
 * with this package in the file LICENSE.txt.
7
 * It is also available through the world-wide-web at this URL:
8
 * http://www.opensource.org/licenses/bsd-license.php
9
 *
10
 * @category  Xyster
11
 * @package   Xyster_Date
12
 * @copyright Copyright LibreWorks, LLC (http://libreworks.net)
13
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
14
 * @version   $Id$
15
 */
16
namespace Xyster\Date;
17
/**
18
 * A date range
19
 *
20
 * @category  Xyster
21
 * @package   Xyster_Date
22
 * @copyright Copyright LibreWorks, LLC (http://libreworks.net)
23
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
24
 */
25
class Range
26
{
27
    /**
28
     * @var \Zend_Date
29
     */
30
    protected $_start;
31
32
    /**
33
     * @var \Zend_Date
34
     */
35
    protected $_end;
36
37
    /**
38
     * A date range
39
     *
40
     * @param \Zend_Date $start The starting date
41
     * @param \Zend_Date $end The ending date
42
     * @throws \Zend_Date_Exception if the end date occurs before the start
43
     */
44
    public function __construct( \Zend_Date $start, \Zend_Date $end )
45
    {
46 6
        if ( $end->isEarlier($start) ) {
47 1
            require_once 'Zend/Date/Exception.php';
48 1
            throw new \Zend_Date_Exception('The end date occurs before the start date');
49
        }
50 6
        $this->_start = $start;
51 6
        $this->_end = $end;
52
    }
53
54
    /**
55
     * Gets the ending date
56
     *
57
     * @return Zend_Date the ending date
58
     */
59
    public function getEnd()
60
    {
61 2
        return clone $this->_end;
62
    }
63
64
    /**
65
     * Gets the beginning date
66
     *
67
     * @return Zend_Date the beginning date
68
     */
69
    public function getStart()
70
    {
71 1
        return clone $this->_start;
72
    }
73
74
    /**
75
     * Gets the timespan between these dates
76
     *
77
     * The part and locale are the same as used in many Zend_Date methods.
78
     *
79
     * @param  string $part OPTIONAL Part of the date to sub, if null the timestamp is subtracted
80
     * @param  mixed $locale OPTIONAL Locale as a Zend_Locale or a string for parsing input
81
     * @return mixed the timespan
82
     */
83
    public function getTimespan($part = \Zend_Date::TIMESTAMP, $locale = null)
84
    {
85 1
        return $this->getEnd()->sub($this->_start, $part, $locale);
86
    }
87
88
    /**
89
     * Tests to see if the supplied date is within this range
90
     *
91
     * The part and locale are the same as used in many Zend_Date methods.
92
     *
93
     * @param mixed $date Date or datepart to compare with the date object
94
     * @param string $part OPTIONAL Part of the date to compare, if null the timestamp is compared
95
     * @param mixed $locale OPTIONAL Locale as a \Zend_Locale or a string for parsing input
96
     * @return boolean
97
     * @throws \Zend_Date_Exception
98
     */
99
    public function isWithin( $date, $part = \Zend_Date::TIMESTAMP, $locale = null )
100
    {
101 1
        return ($this->_start->isEarlier($date, $part, $locale) ||
102 1
            $this->_start->equals($date, $part, $locale)) &&
103 1
            ($this->_end->isLater($date, $part, $locale) ||
104 1
            $this->_end->equals($date, $part, $locale));
105
    }
106
107
    /**
108
     * Returns the string representation of this object
109
     *
110
     * The dates are separated by an En Dash (U+2013)
111
     *
112
     * @magic
113
     * @return string
114
     */
115
    public function __toString()
116
    {
117 1
        return $this->_start . '–' . $this->_end;
118
    }
119 1
}


Report generated at 2010-10-18T17:19:48-04:00