final class IntervalArithmetic
    implements Scalar
    uses Snapshot
Public API: explicitly declared with @visibility public.

Date arithmetic with a trailing interval: date + INTERVAL n unit or date - INTERVAL n unit (Item_date_add_interval).

It belongs to the additive level of bit_expr and associates to the left with + and - (MYSQL-PRECEDENCE-001).

Rule: MYSQL-INTERVAL-ARITHMETIC-001. Facts: the type follows MYSQL-TEMPORAL-RESULT-001; the result is NULL for an invalid date, so it can always be NULL. Terminates: the operand and the quantity are strict parts. Source: https://dev.mysql.com/doc/refman/8.4/en/date-and-time-functions.html#function_date-add. Status: Implemented.

Subtracting an intervaldoctest
$query = (new \SqlSemantics\Platform\MySql\Semantics())->analyze("SELECT a FROM t WHERE DATE '2024-01-31' - INTERVAL 1 MONTH");
    [$query->statement->where->subtract, $query->facts->scalar($query->statement->where)->type->descriptor->name()] // => [true, 'DATE']

Properties§

public Scalar $operand
public Interval $interval
public bool $subtract = false

Methods§

public function __construct(
    public Scalar $operand,
    public Interval $interval,
    public bool $subtract = false,
)

Parameters

$operandScalarThe date or time value
$intervalIntervalThe interval added or subtracted
$subtractboolWhether the interval is subtracted
Calls 4
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFact

Derives the operand and the quantity and the temporal type of the result.

Parameters

$derivationDerivation
$environmentEnvironment

Returns

Calls 7
public function render(Output $out): void

Writes the operand, the sign and the interval.

Parameters

$outOutput
Test cases 2
Calls 1

Test cases 5§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 4
Other tests reaching this symbol 1

Relations§

Instantiated in 1
Type checks 2