Skip to content

Commit

Permalink
Merge pull request #59 from adangel/issue-58
Browse files Browse the repository at this point in the history
Support time literals in SOQL queries
  • Loading branch information
pwrightcertinia authored Dec 14, 2024
2 parents a79a8ae + f00fc84 commit e715cbc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions antlr/ApexLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,10 @@ NEXT_N_FISCAL_YEARS_N : 'next_n_fiscal_years';
LAST_N_FISCAL_YEARS_N : 'last_n_fiscal_years';
N_FISCAL_YEARS_AGO_N : 'n_fiscal_years_ago';

// SOQL Date literal
// SOQL Date and Time literals
DateLiteral: Digit Digit Digit Digit '-' Digit Digit '-' Digit Digit;
DateTimeLiteral: DateLiteral 't' Digit Digit ':' Digit Digit ':' Digit Digit ('z' | (('+' | '-') Digit+ ( ':' Digit+)? ));
TimeLiteral: Digit Digit ':' Digit Digit ':' Digit Digit ('.' Digit+ )? ('z' | (('+' | '-') Digit+ ( ':' Digit+)? ));
DateTimeLiteral: DateLiteral 't' TimeLiteral;

// SOQL Currency literal
// (NOTE: this is also a valid Identifier)
Expand Down
1 change: 1 addition & 0 deletions antlr/ApexParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ value
| signedNumber
| StringLiteral
| DateLiteral
| TimeLiteral
| DateTimeLiteral
| dateFormula
| IntegralCurrencyLiteral (DOT IntegerLiteral?)?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,14 @@ void testFormatWithAggregate() {
assertNotNull(context);
assertEquals(0, parserAndCounter.getValue().getNumErrors());
}

@Test
void timeLiteral() {
Map.Entry<ApexParser, SyntaxErrorCounter> parserAndCounter = createParser(
"[SELECT Break__c,Check_Out__c FROM VMS_Time_Card_Item__c WHERE Time_Card__c =:timeCard.Id AND Check_Out__c = 01:00:00.000Z]"
);
ApexParser.SoqlLiteralContext context = parserAndCounter.getKey().soqlLiteral();
assertNotNull(context);
assertEquals(0, parserAndCounter.getValue().getNumErrors());
}
}
10 changes: 10 additions & 0 deletions npm/src/__tests__/SOQLParserTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,13 @@ test("Format function with aggregate", () => {
expect(context).toBeInstanceOf(SoqlLiteralContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});

test("Time Literal", () => {
const [parser, errorCounter] = createParser(
'[SELECT Break__c,Check_Out__c FROM VMS_Time_Card_Item__c WHERE Time_Card__c =:timeCard.Id AND Check_Out__c = 01:00:00.000Z]'
)
const context = parser.soqlLiteral();

expect(context).toBeInstanceOf(SoqlLiteralContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});

0 comments on commit e715cbc

Please sign in to comment.