Skip to content

DateTimeArbitrary ​

Rasuvaeff\PropertyTesting\Arbitrary\DateTimeArbitrary

Class — Package: property-testing-core — Source — Version: v1.0.0-1-g88fdee2

Implements: ArbitraryInterface

Generates UTC DateTimeImmutable values with microsecond precision, drawn uniformly from an inclusive range, and shrinks toward the Unix epoch (1970-01-01T00:00:00Z) through an integer ladder — clamped to the configured range, the way IntArbitrary shrinks toward zero.

The bounds keep their fraction: min = 12:00:00.5 never generates 12:00:00.0, and a value at .999999 is as likely as one on the second.

Constructor ​

php
__construct(
    ?\DateTimeImmutable $min = NULL,
    ?\DateTimeImmutable $max = NULL,
)
ParameterTypeDefaultDescription
$min?\DateTimeImmutableNULLThe earliest moment, fraction included; the Unix epoch when null.
$max?\DateTimeImmutableNULLThe latest moment, fraction included; 2100-01-01T00:00:00Z when null.

Methods ​

generate() ​

php
generate(Random $random): Shrinkable

Produce one random value from this arbitrary's space, together with its shrink tree. Candidates must be ordered most aggressive first (typically toward a zero/empty/identity element) and every branch of the tree must be finite, so shrinking terminates.

Documentation inherited from ArbitraryInterface.

Throws:

  • LogicException — When PHP cannot build a moment from the drawn microseconds — a range within the integer bounds never triggers it.