Download the PHP package tmihalicka/php-duration without Composer
On this page you can find all versions of the php package tmihalicka/php-duration. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tmihalicka/php-duration
More information about tmihalicka/php-duration
Files in tmihalicka/php-duration
Package php-duration
Short Description PHP Duration Type
License AGPL-3.0-only
Homepage https://github.com/monadial/php-duration
Informations about the package php-duration
php-duration
Missing PHP TimeUnit and Duration library
Installation
Finite Duration
The FiniteDuration class is a representation of a finite duration of time. It provides functionality to perform operations and conversions on durations, such as addition, subtraction, multiplication, division, and conversion to different units of time.
Factory Methods
-
fromTimeUnit(int $length, TimeUnit $unit): FiniteDuration
: Creates a new instance of theFiniteDuration
class from the specified length and time unit. -
fromNanos(int $nanos): FiniteDuration
: Creates a new instance of theFiniteDuration
class from the specified duration in nanoseconds. fromString(string $duration): FiniteDuration
: Creates a new instance of theFiniteDuration
class from a string representation of the duration.
Duration Conversion Methods
toNanos(): int
: Converts the duration to nanoseconds.toMicros(): int
: Converts the duration to microseconds.toMillis(): int
: Converts the duration to milliseconds.toSeconds(): int
: Converts the duration to seconds.toMinutes(): int
: Converts the duration to minutes.toHours(): int
: Converts the duration to hours.toDays(): int
: Converts the duration to days.toUnit(TimeUnit $unit): float
: Converts the duration to the specified time unit.
Arithmetic Operations
add(Duration $other): FiniteDuration
: Adds another duration to the current duration.subtract(Duration $other): FiniteDuration
: Subtracts another duration from the current duration.multiply(int $factor): FiniteDuration
: Multiplies the duration by a factor.division(int $divisor): FiniteDuration
: Divides the duration by a divisor.
Other Methods
isFinite(): bool
: Checks if the duration is finite.equals(Duration $other): bool
: Checks if the current duration is equal to another duration.toCoarsest(): Duration
: Converts the duration to the coarsest possible unit.asDateTime(): DateTimeImmutable
: Converts the duration to aDateTimeImmutable
object.
Exceptions
The FiniteDuration
class may throw the following exceptions:
FiniteDurationBoundary
: Thrown when the duration exceeds the maximum or minimum value allowed by the time unit.NanosecondsAreNotConvertibleToDateTime
: Thrown when attempting to convert a duration in nanoseconds to aDateTimeImmutable
object (nanoseconds cannot be represented as a valid date and time).UnableToConvertToDateTime
: Thrown when the duration cannot be converted to aDateTimeImmutable
object due to limitations or errors.
Please note that this is just an overview of the FiniteDuration
class and its available methods. For detailed information on each method and its usage, refer to the class implementation and documentation.