-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathYear.php
More file actions
107 lines (93 loc) · 2.45 KB
/
Year.php
File metadata and controls
107 lines (93 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
namespace Icecave\Chrono\Interval;
use Icecave\Chrono\Date;
use Icecave\Chrono\Detail\Calendar;
use Icecave\Chrono\Detail\Iso8601;
use Icecave\Chrono\Iso8601Interface;
use Icecave\Chrono\TimePointInterface;
class Year extends AbstractInterval implements Iso8601Interface
{
/**
* @param int $ordinal The year number.
*/
public function __construct($ordinal)
{
$this->ordinal = $ordinal;
}
/**
* @param TimePointInterface $timePoint The time point to create from.
*
* @return Year The Year constructed from the given time point.
*/
public static function fromTimePoint(TimePointInterface $timePoint)
{
return new self($timePoint->year());
}
/**
* Standard year format:
* YYYY
*
* @link http://en.wikipedia.org/wiki/ISO_8601#Calendar_dates
*
* Note: Negative years (BC) are not supported.
*
* @param string $isoString A string containing a year in any ISO-8601 compatible year format.
*
* @return Year The Year constructed from the ISO compatible string.
*/
public static function fromIsoString($isoString)
{
$year = Iso8601::parseYear($isoString);
return new self($year);
}
/**
* @return int The year number.
*/
public function ordinal()
{
return $this->ordinal;
}
/**
* @return Date The start of the interval.
*/
public function start()
{
return new Date($this->ordinal(), 1, 1);
}
/**
* @return Date The end of the interval.
*/
public function end()
{
return new Date($this->ordinal() + 1, 1, 1);
}
/**
* @return int The number of days included in this interval.
*/
public function numberOfDays()
{
return Calendar::daysInyear($this->ordinal());
}
/**
* @return bool True if this year interval represents a leap year; otherwise, false.
*/
public function isLeapYear()
{
return Calendar::isLeapYear($this->ordinal());
}
/**
* @return string A string representing this object in an ISO compatible year format (YYYY).
*/
public function isoString()
{
return Iso8601::formatYear($this->ordinal());
}
/**
* @return string A string representing this object in an ISO compatible year format (YYYY).
*/
public function __toString()
{
return $this->isoString();
}
private $ordinal;
}