Skip to content

Commit cd3f724

Browse files
committed
add back functions
1 parent cf060cc commit cd3f724

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
lines changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
"autoload": {
77
"psr-4": {
88
"Withinboredom\\Time\\": "src/"
9-
}
9+
},
10+
"files": [
11+
"src/functions.php"
12+
]
1013
},
1114
"authors": [
1215
{

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readme.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ sleep((new \Withinboredom\Time\Minutes(5))->inSeconds())
2020
usleep((new \Withinboredom\Time\Milliseconds(0.25))->inMicroseconds())
2121
```
2222

23+
or in a simplified form:
24+
25+
```php
26+
// sleep for 300 seconds
27+
sleep(Minutes(5)->inSeconds());
28+
29+
// sleep for a quarter of a millisecond
30+
usleep(Milliseconds(0.25)->inMicroseconds);
31+
```
32+
2333
If you need to change the conversion rates, just create a new standard:
2434

2535
```php

src/functions.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Withinboredom\Time;
4+
5+
function Microseconds(float $time, TimeAndSpaceInterface $spacetime = new StandardEarthTime()): ConvertedTimeInterface { return new Microseconds($time, $spacetime); }
6+
function Milliseconds(float $time, TimeAndSpaceInterface $spacetime = new StandardEarthTime()): ConvertedTimeInterface { return new Milliseconds($time, $spacetime); }
7+
function Seconds(float $time, TimeAndSpaceInterface $spacetime = new StandardEarthTime()): ConvertedTimeInterface { return new Seconds($time, $spacetime); }
8+
function Minutes(float $time, TimeAndSpaceInterface $spacetime = new StandardEarthTime()): ConvertedTimeInterface { return new Minutes($time, $spacetime); }
9+
function Hours(float $time, TimeAndSpaceInterface $spacetime = new StandardEarthTime()): ConvertedTimeInterface { return new Hours($time, $spacetime); }
10+
function Days(float $time, TimeAndSpaceInterface $spacetime = new StandardEarthTime()): ConvertedTimeInterface { return new Days($time, $spacetime); }
11+
function Weeks(float $time, TimeAndSpaceInterface $spacetime = new StandardEarthTime()): ConvertedTimeInterface { return new Weeks($time, $spacetime); }

tests/ConversionTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@ class ConversionTest extends TestCase
1313
private const EXPECTED_SECONDS = 1209600.0;
1414
private const EXPECTED_MILLISECONDS = 1209600000.0;
1515
private const EXPECTED_MICROSECONDS = 1209600000000.0;
16-
16+
17+
public function testFunctions() {
18+
$this->assertSame(2.0, Microseconds(2)->inMicroseconds());
19+
$this->assertSame(2.0, Milliseconds(2)->inMilliseconds());
20+
$this->assertSame(2.0, Seconds(2)->inSeconds());
21+
$this->assertSame(2.0, Minutes(2)->inMinutes());
22+
$this->assertSame(2.0, Hours(2)->inHours());
23+
$this->assertSame(2.0, Days(2)->inDays());
24+
$this->assertSame(2.0, Weeks(2)->inWeeks());
25+
}
26+
1727
public function testMicroseconds()
1828
{
1929
$weeks = Weeks::from(self::EXPECTED_MICROSECONDS)->microseconds();

0 commit comments

Comments
 (0)