1 | <?php |
||
16 | class TimeValueCalculator { |
||
17 | |||
18 | /** |
||
19 | * Average length of a year in the Gregorian calendar in seconds, calculated via |
||
20 | * 365 + 1 / 4 - 1 / 100 + 1 / 400 = 365.2425 days. |
||
21 | */ |
||
22 | const SECONDS_PER_GREGORIAN_YEAR = 31556952; |
||
23 | |||
24 | /** |
||
25 | * This returns a Unix timestamp from a TimeValue similar to PHP's mk_time() (or strtotime()), |
||
26 | * but with no range limitations. Data type is float because PHP's 32 bit integer would |
||
27 | * clip in the year 2038. |
||
28 | * |
||
29 | * @param TimeValue $timeValue |
||
30 | * |
||
31 | * @return float seconds since 1970-01-01T00:00:00Z |
||
32 | */ |
||
33 | 34 | public function getTimestamp( TimeValue $timeValue ) { |
|
36 | |||
37 | /** |
||
38 | * @param string $time an ISO 8601 date and time |
||
39 | * @param int $timezone offset from UTC in minutes |
||
40 | * |
||
41 | * @throws InvalidArgumentException |
||
42 | * @return float seconds since 1970-01-01T00:00:00Z |
||
43 | */ |
||
44 | 34 | private function getSecondsSinceUnixEpoch( $time, $timezone = 0 ) { |
|
73 | |||
74 | /** |
||
75 | * @param float $year |
||
76 | * |
||
77 | * @return bool if the year is a leap year in the Gregorian calendar |
||
78 | */ |
||
79 | 68 | public function isLeapYear( $year ) { |
|
86 | |||
87 | /** |
||
88 | * @param float $year |
||
89 | * |
||
90 | * @return float The number of leap years since year 1. To be more precise: The number of |
||
91 | * leap days in the range between 31 December of year 1 and 31 December of the given year. |
||
92 | */ |
||
93 | 68 | public function getNumberOfLeapYears( $year ) { |
|
97 | |||
98 | /** |
||
99 | * @param int $precision One of the TimeValue::PRECISION_... constants |
||
100 | * |
||
101 | * @throws InvalidArgumentException |
||
102 | * @return float number of seconds in one unit of the given precision |
||
103 | */ |
||
104 | 8 | public function getSecondsForPrecision( $precision ) { |
|
127 | |||
128 | } |
||
129 |