classDateArithmetic
final class DateArithmetic
implements Scalar
uses Snapshot
@visibility public.A call of DATE_ADD(date, INTERVAL expr unit) or DATE_SUB(date, INTERVAL expr unit).
Rule: MYSQL-DATE-ARITHMETIC-001. The server builds Item_date_add_interval. ADDDATE and SUBDATE with an INTERVAL argument are the same functions (synonyms in CallNoise) and are written as DATE_ADD and DATE_SUB. The result type follows the date and the unit (ResultTyping::dateArithmetic); the result is NULL when an operand is NULL or the date is invalid. Terminates: the operands 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 ADDDATE(DATE '2024-01-01', INTERVAL 1 MONTH) AS d");
[$query->field(0)->type->descriptor->name(), $query->toString()] // => ['DATE', "SELECT DATE_ADD(DATE '2024-01-01', INTERVAL 1 MONTH) AS d"]Properties§
public bool $subtractpublic Scalar $datepublic Scalar $quantitypublic IntervalUnit $unitMethods§
public function __construct(
public bool $subtract,
public Scalar $date,
public Scalar $quantity,
public IntervalUnit $unit,
)Parameters
$subtract | bool | Whether the interval is subtracted (DATE_SUB) |
$date | Scalar | The date or time |
$quantity | Scalar | The number of units |
$unit | IntervalUnit | The unit |
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives the operands and the type the date and the unit give.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 6
- method-call Arguments::one() line 54
- new Arguments line 54
- new ScalarFact line 57
- method-call ResultTyping::dateArithmetic() line 57
- new ResultTyping line 57
- class-const Nullability::Nullable() line 57
public function render(Output $out): voidTest cases 3§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.