classTemporalLiteral
final class TemporalLiteral
implements Scalar
uses Snapshot
@visibility public.A standard date and time literal: DATE 'text', TIME 'text' or TIMESTAMP 'text'.
Rule: MYSQL-TEMPORAL-LITERAL-001. Facts: DATE yields DATE, TIME yields TIME, and TIMESTAMP yields DATETIME; the fractional seconds precision of TIME and DATETIME is the number of digits written after the last decimal point, before an optional time zone offset, at most 6; never NULL. Text the server cannot read as a value of the kind is an error of the statement when it runs and is not decided here. Precision: exact for text the server accepts. Diagnostics: none. A literal spelled under another escape rule than the profile is an invalid construction. Source: https://dev.mysql.com/doc/refman/8.4/en/date-and-time-literals.html, https://dev.mysql.com/doc/refman/8.4/en/fractional-seconds.html. Status: Implemented.
$query = (new \SqlSemantics\Platform\MySql\Semantics())->analyze("SELECT a FROM t WHERE a = TIMESTAMP '2024-01-02 03:04:05.25'");
[$query->statement->where->right->form, $query->statement->where->right->text, $query->statement->where->right->type()->precision] // => [\SqlSemantics\Platform\MySql\Statement\Literal\TemporalForm::Timestamp, '2024-01-02 03:04:05.25', '2']Properties§
public TemporalForm $formpublic string $textpublic EscapeRule $escapes = EscapeRule::BackslashMethods§
public function __construct(
public TemporalForm $form,
public string $text,
public EscapeRule $escapes = EscapeRule::Backslash,
)Parameters
$form | TemporalForm | The keyword of the literal |
$text | string | The decoded text |
$escapes | EscapeRule | The rule the text is spelled under; the rule of the language profile |
Calls 1
- class-const EscapeRule::Backslash() line 48
public function type(): TemporalAnswers the type of the literal.
Returns
Test cases 3
Called from 1
Calls 9
- class-const TemporalForm::Date() line 57
- new Temporal line 58
- class-const TemporalKind::Date() line 58
- function-call
preg_matchline 60 - function-call
minline 60 - function-call
strlenline 60 - class-const TemporalForm::Time() line 62
- class-const TemporalKind::Time() line 62
- class-const TemporalKind::DateTime() line 62
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives the temporal type; a literal is never NULL.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 6
- static-call Check::input() line 70
- static-call EscapeRule::under() line 70
- new ScalarFact line 72
- new Known line 72
- method-call TemporalLiteral::type() line 72
- class-const Nullability::NotNull() line 72
public function render(Output $out): voidWrites the keyword and the quoted text.
Parameters
$out | Output |
Calls 4
- method-call Output::keyword() line 80
- method-call Strings::encode() line 80
- new Strings line 80
- class-const EscapeRule::Backslash() line 80
Test cases 12§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 5
TemporalLiteralTest::testDeriveScalarAnswersTheTemporalTypeThatIsNeverNullcallsTemporalLiteralTest::testDeriveScalarRejectsALiteralSpelledUnderTheOtherEscapeRulecallsTemporalLiteralTest::testTypeAnswersDateTimeForTimestampAndIgnoresATimeZoneOffsetcallsTemporalLiteralTest::testTypeAnswersDateWithoutAPrecisioncallsTemporalLiteralTest::testTypeCountsTheFractionalDigitsUpToSixcalls
Other tests reaching this symbol 7
LiteralRuleTest::testLiteralLowersEveryLiteralFormcallsKeywordCallTest::testDeriveScalarTypesAddDateAsDateArithmeticcallsDateArithmeticTest::testDeriveScalarFollowsTheDateAndTheUnitcallsTimestampCallTest::testDeriveScalarTypesADifferenceAsAnIntegercallsTimestampCallTest::testDeriveScalarTypesAnAdditionAsDateArithmeticcallsIntervalAdditionTest::testDeriveScalarMakesADateTimeForATimeUnitcallsIntervalArithmeticTest::testDeriveScalarKeepsADateForADateUnitcalls