|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SubjectivePHP\Durations; |
|
4
|
|
|
|
|
5
|
|
|
abstract class Seconds |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* @var int |
|
9
|
|
|
*/ |
|
10
|
|
|
const ONE_SECOND = 1; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var int |
|
14
|
|
|
*/ |
|
15
|
|
|
const MINUTE_IN_SECONDS = self::ONE_SECOND * 60; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var int |
|
19
|
|
|
*/ |
|
20
|
|
|
const HOUR_IN_SECONDS = self::MINUTE_IN_SECONDS * 60; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var int |
|
24
|
|
|
*/ |
|
25
|
|
|
const DAY_IN_SECONDS = self::HOUR_IN_SECONDS * 24; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var int |
|
29
|
|
|
*/ |
|
30
|
|
|
const WEEK_IN_SECONDS = self::DAY_IN_SECONDS * 7; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var int |
|
34
|
|
|
*/ |
|
35
|
|
|
const MONTH_IN_SECONDS = self::DAY_IN_SECONDS * 30; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var int |
|
39
|
|
|
*/ |
|
40
|
|
|
const YEAR_IN_SECONDS = self::DAY_IN_SECONDS * 365; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Returns the given number of minutes represented in seconds. |
|
44
|
|
|
* |
|
45
|
|
|
* @param int $minutes The value to covert to minutes. |
|
46
|
|
|
* |
|
47
|
|
|
* @return int |
|
48
|
|
|
*/ |
|
49
|
|
|
public static function inMinutes(int $minutes) : int |
|
50
|
|
|
{ |
|
51
|
|
|
return $minutes * self::MINUTE_IN_SECONDS; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Returns the given number of hours represented in seconds. |
|
56
|
|
|
* |
|
57
|
|
|
* @param int $hours The value to covert to seconds. |
|
58
|
|
|
* |
|
59
|
|
|
* @return int |
|
60
|
|
|
*/ |
|
61
|
|
|
public static function inHours(int $hours) : int |
|
62
|
|
|
{ |
|
63
|
|
|
return $hours * self::HOUR_IN_SECONDS; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Returns the given number of days represented in seconds. |
|
68
|
|
|
* |
|
69
|
|
|
* @param int $days The value to covert to seconds. |
|
70
|
|
|
* |
|
71
|
|
|
* @return int |
|
72
|
|
|
*/ |
|
73
|
|
|
public static function inDays(int $days) : int |
|
74
|
|
|
{ |
|
75
|
|
|
return $days * self::DAY_IN_SECONDS; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Returns the given number of weeks represented in seconds. |
|
80
|
|
|
* |
|
81
|
|
|
* @param int $weeks The value to covert to seconds. |
|
82
|
|
|
* |
|
83
|
|
|
* @return int |
|
84
|
|
|
*/ |
|
85
|
|
|
public static function inWeeks(int $weeks) : int |
|
86
|
|
|
{ |
|
87
|
|
|
return $weeks * self::WEEK_IN_SECONDS; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Returns the given number of months represented in seconds. |
|
92
|
|
|
* |
|
93
|
|
|
* @param int $months The value to covert to seconds. |
|
94
|
|
|
* |
|
95
|
|
|
* @return int |
|
96
|
|
|
*/ |
|
97
|
|
|
public static function inMonths(int $months) : int |
|
98
|
|
|
{ |
|
99
|
|
|
return $months * self::MONTH_IN_SECONDS; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Returns the given number of years represented in seconds. |
|
104
|
|
|
* |
|
105
|
|
|
* @param int $years The value to covert to seconds. |
|
106
|
|
|
* |
|
107
|
|
|
* @return int |
|
108
|
|
|
*/ |
|
109
|
|
|
public static function inYears(int $years) : int |
|
110
|
|
|
{ |
|
111
|
|
|
return $years * self::YEAR_IN_SECONDS; |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|