Skip to content

DateRange

Viames Marino edited this page Sep 30, 2026 · 2 revisions

Pair framework: DateRange

Pair\Helpers\DateRange is an immutable value object for half-open date-time intervals [start, end): the start is included and the end is excluded.

Main methods

  • contains(DateTimeInterface $dt): bool
  • overlaps(DateRange $other): bool
  • intersection(DateRange $other): ?DateRange
  • expand(?DateInterval $before = null, ?DateInterval $after = null): DateRange
  • shift(DateInterval $delta): DateRange, shiftBy(string $modifier): DateRange
  • forMonth(), previousMonth(), nextMonth()
  • toArray(string $format = 'Y-m-d H:i:s'): array
  • toSqlParams(...): array, toSqlWhere(string $column, ...): string
  • toPeriod(DateInterval $step, int $options = 0): DatePeriod

Implementation example

$range = new \Pair\Helpers\DateRange(
    new DateTimeImmutable('2026-02-01 00:00:00'),
    new DateTimeImmutable('2026-03-01 00:00:00')
);

$where = $range->toSqlWhere('created_at');
$params = $range->toSqlParams();

$orders = \Pair\Orm\Query::table('orders')
    ->whereRaw($where, $params)
    ->get();

Notes

  • Constructor validates start < end.
  • Supports month helpers and localization-aware formatting methods.

See also: Query, QueryFilter.

Clone this wiki locally