Skip to content

Commit 35d7b86

Browse files
committed
major overhaul and simplification
1 parent badb633 commit 35d7b86

File tree

11 files changed

+206
-461
lines changed

11 files changed

+206
-461
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
}
1919
],
2020
"require": {
21-
"php": "^8.0"
21+
"php": "^8.2"
2222
},
2323
"require-dev": {
2424
"pestphp/pest": "^2.34.8",
25-
"laravel/pint": "^1.16.1"
25+
"laravel/pint": "^1.16.2"
2626
},
2727
"config": {
2828
"allow-plugins": {

composer.lock

Lines changed: 34 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readme.md

Lines changed: 7 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# A really simple library for converting time
22

3-
This is a simple library for interacting with time durations. You can write your code to expect seconds:
3+
This is a simple library for interacting with time durations.
4+
You can write your code to expect time and know that is what you have:
45

56
```php
6-
function sleep(\Withinboredom\Time\AnyTime $time): void {
7-
\sleep($time->inSeconds());
7+
function sleep(\Withinboredom\Time\Time $time): void {
8+
\sleep($time->as(\Withinboredom\Time\TimeUnit::Seconds));
89
}
910

1011
sleep(\Withinboredom\Time\Minutes(5));
@@ -18,64 +19,18 @@ All values of the same time are always strongly equaled to each other:
1819
\Withinboredom\Time\Minutes(60) === \Withinboredom\Time\Hours(1)
1920
```
2021

21-
## Math
22-
23-
If you have the GMP extension installed, you can use math operations.
24-
25-
```php
26-
$minutes = \Withinboredom\Time\Minutes(5);
27-
$hour = $minutes * 6;
28-
```
29-
30-
However, note that this results in a GMP number representing the time in nanoseconds, not an `AnyTime` object. To
31-
convert it back to an `AnyTime` object:
32-
33-
```php
34-
$anytime = AnyTime::fromValue($hour, StandardEarthTime::duration());
35-
```
36-
37-
Thus, you can write attributes that accept time:
38-
39-
```php
40-
#[Attribute(Attribute::TARGET_METHOD)]
41-
class ScheduleEvery {
42-
public AnyTime $schedule;
43-
44-
public function __construct(AnyTime|\GMP $schedule) {
45-
if($schedule instanceof \GMP) {
46-
$schedule = AnyTime::fromValue($schedule, StandardEarthTime::duration());
47-
}
48-
$this->schedule = $schedule;
49-
}
50-
}
51-
52-
#[ScheduleEvery(StandardMinute * 5)] // schedule every 5 minutes
53-
```
54-
5522
## Utilities
5623

5724
There are also a few utility methods:
5825

59-
> ->add(AnyTime)->subtract(AnyTime): AnyTime
26+
> ->add(Time)->subtract(Time): AnyTime
6027
6128
Add and subtract durations.
6229

6330
> ->toDateInterval(): DateInterval
6431
6532
Creates a date interval for use in other things.
6633

67-
## Conversions
68-
69-
If you need to change the conversion rates, create a new standard:
70-
71-
```php
72-
class Mars implements \Withinboredom\Time\TimeAndSpaceInterface {
73-
/// ... fill in the blanks
74-
}
75-
```
76-
77-
This can be (mis)used to allow for very short times in unit tests (to make a week pass by in literally microseconds).
78-
7934
## Units
8035

8136
- Nanoseconds
@@ -90,16 +45,11 @@ This can be (mis)used to allow for very short times in unit tests (to make a wee
9045

9146
> Why not months/years?
9247
93-
There's no set days in a month/year, so it's better to use `DateInterval` for those types of measures.
48+
There's no set days in a month/year, so its better to use `DateInterval` for those types of measures.
9449

9550
> Why does this exist?
9651
97-
I don't
98-
like [magic numbers](https://en.wikipedia.org/wiki/Magic_number_(programming)#:~:text=Magic%20numbers%20are%20common%20in%20programs%20across%20many,have%20such%20constants%20that%20identify%20the%20contained%20data.).
99-
100-
> Can I convert between standards?
101-
102-
Not yet.
52+
I don’t like [magic numbers](https://en.wikipedia.org/wiki/Magic_number_(programming)#:~:text=Magic%20numbers%20are%20common%20in%20programs%20across%20many,have%20such%20constants%20that%20identify%20the%20contained%20data.).
10353

10454
> How performant is this?
10555

0 commit comments

Comments
 (0)