Skip to content

Commit 4fc34ca

Browse files
committed
Add Seconds and Minutes
1 parent 017dc1e commit 4fc34ca

4 files changed

Lines changed: 362 additions & 0 deletions

File tree

src/Minutes.php

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
3+
namespace SubjectivePHP\Durations;
4+
5+
abstract class Minutes
6+
{
7+
/**
8+
* @var int
9+
*/
10+
const ONE_MINUTE = 1;
11+
12+
/**
13+
* @var int
14+
*/
15+
const HOUR_IN_MINUTES = self::ONE_MINUTE * 60;
16+
17+
/**
18+
* @var int
19+
*/
20+
const DAY_IN_MINUTES = self::HOUR_IN_MINUTES * 24;
21+
22+
/**
23+
* @var int
24+
*/
25+
const WEEK_IN_MINUTES = self::DAY_IN_MINUTES * 7;
26+
27+
/**
28+
* @var int
29+
*/
30+
const MONTH_IN_MINUTES = self::DAY_IN_MINUTES * 30;
31+
32+
/**
33+
* @var int
34+
*/
35+
const YEAR_IN_MINUTES = self::DAY_IN_MINUTES * 365;
36+
37+
/**
38+
* Returns the given number of hours represented in seconds.
39+
*
40+
* @param int $hours The value to covert to seconds.
41+
*
42+
* @return int
43+
*/
44+
public static function inHours(int $hours) : int
45+
{
46+
return $hours * self::HOUR_IN_MINUTES;
47+
}
48+
49+
/**
50+
* Returns the given number of days represented in seconds.
51+
*
52+
* @param int $days The value to covert to seconds.
53+
*
54+
* @return int
55+
*/
56+
public static function inDays(int $days) : int
57+
{
58+
return $days * self::DAY_IN_MINUTES;
59+
}
60+
61+
/**
62+
* Returns the given number of weeks represented in seconds.
63+
*
64+
* @param int $weeks The value to covert to seconds.
65+
*
66+
* @return int
67+
*/
68+
public static function inWeeks(int $weeks) : int
69+
{
70+
return $weeks * self::WEEK_IN_MINUTES;
71+
}
72+
73+
/**
74+
* Returns the given number of months represented in seconds.
75+
*
76+
* @param int $months The value to covert to seconds.
77+
*
78+
* @return int
79+
*/
80+
public static function inMonths(int $months) : int
81+
{
82+
return $months * self::MONTH_IN_MINUTES;
83+
}
84+
85+
/**
86+
* Returns the given number of years represented in seconds.
87+
*
88+
* @param int $years The value to covert to seconds.
89+
*
90+
* @return int
91+
*/
92+
public static function inYears(int $years) : int
93+
{
94+
return $years * self::YEAR_IN_MINUTES;
95+
}
96+
}

src/Seconds.php

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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 minutes.
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 minutes.
56+
*
57+
* @param int $hours The value to covert to minutes.
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 minutes.
68+
*
69+
* @param int $days The value to covert to minutes.
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 minutes.
80+
*
81+
* @param int $weeks The value to covert to minutes.
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 minutes.
92+
*
93+
* @param int $months The value to covert to minutes.
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 minutes.
104+
*
105+
* @param int $years The value to covert to minutes.
106+
*
107+
* @return int
108+
*/
109+
public static function inYears(int $years) : int
110+
{
111+
return $years * self::YEAR_IN_SECONDS;
112+
}
113+
}

tests/MinutesTest.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
namespace SubjectivePHPTest\Durations;
4+
5+
use SubjectivePHP\Durations\Minutes;
6+
use PHPUnit\Framework\TestCase;
7+
8+
/**
9+
* @coversDefaultClass \SubjectivePHP\Durations\Minutes
10+
*/
11+
final class MinutesTest extends TestCase
12+
{
13+
/**
14+
* @test
15+
* @covers ::inHours
16+
*/
17+
public function inHoursCalculatesValue()
18+
{
19+
for ($i = 0; $i < 60; $i++) {
20+
$this->assertSame(60 * $i, Minutes::inHours($i));
21+
}
22+
}
23+
24+
/**
25+
* @test
26+
* @covers ::inDays
27+
*/
28+
public function inDaysCalculatesValue()
29+
{
30+
for ($i = 0; $i < 60; $i++) {
31+
$expected = 60 * 24 * $i;
32+
$this->assertSame($expected, Minutes::inDays($i));
33+
}
34+
}
35+
36+
/**
37+
* @test
38+
* @covers ::inWeeks
39+
*/
40+
public function inWeeksCalculatesValue()
41+
{
42+
for ($i = 0; $i < 60; $i++) {
43+
$expected = 60 * 24 * 7 * $i;
44+
$this->assertSame($expected, Minutes::inWeeks($i));
45+
}
46+
}
47+
48+
/**
49+
* @test
50+
* @covers ::inMonths
51+
*/
52+
public function inMonthsCalculatesValue()
53+
{
54+
for ($i = 0; $i < 60; $i++) {
55+
$expected = 60 * 24 * 30 * $i;
56+
$this->assertSame($expected, Minutes::inMonths($i));
57+
}
58+
}
59+
60+
/**
61+
* @test
62+
* @covers ::inYears
63+
*/
64+
public function inYearsCalculatesValue()
65+
{
66+
for ($i = 0; $i < 60; $i++) {
67+
$expected = 60 * 24 * 365 * $i;
68+
$this->assertSame($expected, Minutes::inYears($i));
69+
}
70+
}
71+
}

tests/SecondsTest.php

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
namespace SubjectivePHPTest\Durations;
4+
5+
use SubjectivePHP\Durations\Seconds;
6+
use PHPUnit\Framework\TestCase;
7+
8+
/**
9+
* @coversDefaultClass \SubjectivePHP\Durations\Seconds
10+
*/
11+
final class SecondsTest extends TestCase
12+
{
13+
/**
14+
* @test
15+
* @covers ::inMinutes
16+
*/
17+
public function inMinutesCalculatesValue()
18+
{
19+
for ($i = 0; $i < 60; $i++) {
20+
$this->assertSame(60 * $i, Seconds::inMinutes($i));
21+
}
22+
}
23+
24+
/**
25+
* @test
26+
* @covers ::inHours
27+
*/
28+
public function inHoursCalculatesValue()
29+
{
30+
for ($i = 0; $i < 60; $i++) {
31+
$this->assertSame(60 * 60 * $i, Seconds::inHours($i));
32+
}
33+
}
34+
35+
/**
36+
* @test
37+
* @covers ::inDays
38+
*/
39+
public function inDaysCalculatesValue()
40+
{
41+
for ($i = 0; $i < 60; $i++) {
42+
$expected = 60 * 60 * 24 * $i;
43+
$this->assertSame($expected, Seconds::inDays($i));
44+
}
45+
}
46+
47+
/**
48+
* @test
49+
* @covers ::inWeeks
50+
*/
51+
public function inWeeksCalculatesValue()
52+
{
53+
for ($i = 0; $i < 60; $i++) {
54+
$expected = 60 * 60 * 24 * 7 * $i;
55+
$this->assertSame($expected, Seconds::inWeeks($i));
56+
}
57+
}
58+
59+
/**
60+
* @test
61+
* @covers ::inMonths
62+
*/
63+
public function inMonthsCalculatesValue()
64+
{
65+
for ($i = 0; $i < 60; $i++) {
66+
$expected = 60 * 60 * 24 * 30 * $i;
67+
$this->assertSame($expected, Seconds::inMonths($i));
68+
}
69+
}
70+
71+
/**
72+
* @test
73+
* @covers ::inYears
74+
*/
75+
public function inYearsCalculatesValue()
76+
{
77+
for ($i = 0; $i < 60; $i++) {
78+
$expected = 60 * 60 * 24 * 365 * $i;
79+
$this->assertSame($expected, Seconds::inYears($i));
80+
}
81+
}
82+
}

0 commit comments

Comments
 (0)