withinboredom / time
Converting time to units
Installs: 1 329
Dependents: 1
Suggesters: 0
Security: 0
Stars: 12
Watchers: 4
Forks: 6
Open Issues: 1
Requires
- php: ^8.2
Requires (Dev)
- laravel/pint: ^1.16.2
- pestphp/pest: ^2.34.8
README
This is a simple library for interacting with time durations. You can write your code to expect time and know that is what you have:
function sleep(\Withinboredom\Time\Time $time): void { \sleep($time->as(\Withinboredom\Time\TimeUnit::Seconds)); } sleep(\Withinboredom\Time\Minutes(5));
Equality
All values of the same time are always strongly equaled to each other:
\Withinboredom\Time\Minutes(60) === \Withinboredom\Time\Hours(1)
Utilities
There are also a few utility methods:
->add(Time)->subtract(Time): AnyTime
Add and subtract durations.
->toDateInterval(): DateInterval
Creates a date interval for use in other things.
Units
- Nanoseconds
- Microseconds
- Milliseconds
- Minutes
- Hours
- Days
- Weeks
FAQ
Why not months/years?
There's no set days in a month/year, so it’s better to use DateInterval
for those types of measures.
Why does this exist?
I don’t like magic numbers.
How performant is this?
The main overhead is in autoloading and function-call overhead. Thus, if realtime performance is a concern, you might want to stick to magic numbers.
Developing
If you wish to create a PR or update the code here:
- Clone the repo
composer install
to install test dependenciesyarn
to install git hooks for formatting- Open in favorite IDE.
Code Standards
Per coding styles are followed.