classIntervalArithmetic
final class IntervalArithmetic
implements Scalar
uses Snapshot
@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.
$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 $operandpublic Interval $intervalpublic bool $subtract = falseMethods§
public function __construct(
public Scalar $operand,
public Interval $interval,
public bool $subtract = false,
)Parameters
$operand | Scalar | The date or time value |
$interval | Interval | The interval added or subtracted |
$subtract | bool | Whether the interval is subtracted |
Calls 4
- static-call Check::input() line 47
- method-call Precedence::fits() line 47
- new Precedence line 47
- class-const Precedence::ADDITIVE() line 47
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives the operand and the quantity and the temporal type of the result.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 7
- new Operands line 55
- method-call Operands::single() line 56
- method-call Derivation::scalar() line 56
- new ScalarFact line 59
- method-call TemporalResult::interval() line 59
- new TemporalResult line 59
- class-const Nullability::Nullable() line 59
public function render(Output $out): voidWrites the operand, the sign and the interval.
Parameters
$out | Output |
Test cases 2
Calls 1
- method-call Output::node() line 67
Test cases 5§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.