Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3894,6 +3894,27 @@ private class MockDatabaseTest {
List<Opportunity> opportunities = MockDatabase.query('SELECT Id FROM Opportunity WHERE CloseDate = LAST_QUARTER');
Test.stopTest();

Assert.areEqual(3, opportunities.size(), 'Incorrect number of opportunities');
}

@isTest
static void ensureNextQuarterInWhereClause() {
List<Opportunity> oppList = new List<Opportunity>();
Date startOfYear = Date.newInstance(Gmt.today().year(), 1, 1);
for(Integer i = 0; i < 12; i++) {
oppList.add(new Opportunity(
Name = 'Opp' + i,
CloseDate = startOfYear.addMonths(i)
));
}

MockDatabase.doInsert(oppList, true);

Test.startTest();
List<Opportunity> opportunities = MockDatabase.query('SELECT Id FROM Opportunity WHERE CloseDate = NEXT_QUARTER');
Test.stopTest();


Assert.areEqual(3, opportunities.size(), 'Incorrect number of opportunities');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public with sharing class DateLiteralComparableFactory {
Token.LAST_N_WEEKS_LITERAL => LastNWeeksComparable.class,
Token.N_MONTHS_AGO_LITERAL => NMonthsAgoComparable.class,
Token.THIS_QUARTER_LITERAL => ThisQuarterComparable.class,
Token.LAST_QUARTER_LITERAL => LastQuarterComparable.class
Token.LAST_QUARTER_LITERAL => LastQuarterComparable.class,
Token.NEXT_QUARTER_LITERAL => NextQuarterComparable.class
};

@TestVisible
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @description Compares the NEXT_QUARTER token
* @author Zackary Frazier
* @since 1/2/2024
*/
public with sharing class NextQuarterComparable extends DateLiteralComparable {
/**
* @description Returns true if the fieldValue is equal to the NEXT_QUARTER token
* @param fieldValue `Datetime`
* @return `Boolean`
*/
public override Boolean isEqual(Datetime fieldValue) {
Datetime startOfNextQuarter = Gmt.startOfThisCalendarQuarter().addMonths(3);
Datetime endOfNextQuarter = startOfNextQuarter.addMonths(3);
return startOfNextQuarter <= fieldValue && fieldValue < endOfNextQuarter;
}

/**
* @description Returns true if the fieldValue is greater than the NEXT_QUARTER token
* @param fieldValue `Datetime`
* @return `Boolean`
*/
public override Boolean isGreaterThan(Datetime fieldValue) {
Datetime startOfNextQuarter = Gmt.startOfThisCalendarQuarter().addMonths(3);
Datetime endOfNextQuarter = startOfNextQuarter.addMonths(3);
return fieldValue >= endOfNextQuarter;
}

/**
* @description Returns true if the fieldValue is less than the NEXT_QUARTER token
* @param fieldValue `Datetime`
* @return `Boolean`
*/
public override Boolean isLessThan(Datetime fieldValue) {
Datetime startOfNextQuarter = Gmt.startOfThisCalendarQuarter().addMonths(3);
return fieldValue < startOfNextQuarter;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>62.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
@isTest
private class NextQuarterComparableTest {

@isTest
static void ensureIsEqualWorks() {
NextQuarterComparable nextQuarter = new NextQuarterComparable();
Datetime startOfNextQuarter = Gmt.startOfThisCalendarQuarter().addMonths(3);

Assert.isFalse(nextQuarter.isEqual(startOfNextQuarter.addDays(-1)), 'Start of next quarter should not be equal to the day before');
Assert.isTrue(nextQuarter.isEqual(startOfNextQuarter), 'Start of next quarter should be equal to itself');
Assert.isTrue(nextQuarter.isEqual(startOfNextQuarter.addDays(1)), 'Start of next quarter should be equal to the day after');
Assert.isTrue(nextQuarter.isEqual(startOfNextQuarter.addMonths(1)), 'Start of next quarter should be equal to a month after');
Assert.isTrue(nextQuarter.isEqual(startOfNextQuarter.addMonths(2)), 'Start of next quarter should be equal to two months after');
Assert.isFalse(nextQuarter.isEqual(startOfNextQuarter.addMonths(3)), 'Start of next quarter should not be equal to three months after');

}

@isTest
static void ensuresIsLessThanWorks() {
NextQuarterComparable nextQuarter = new NextQuarterComparable();
Datetime startOfNextQuarter = Gmt.startOfThisCalendarQuarter().addMonths(3);
Assert.isTrue(nextQuarter.isLessThan(startOfNextQuarter.addMonths(-1)), 'One month before should be less than NEXT_QUARTER');
Assert.isFalse(nextQuarter.isLessThan(startOfNextQuarter), 'Start of next quarter should not be less than itself');
}

@isTest
static void ensureIsGreaterThanWorks() {
NextQuarterComparable nextQuarter = new NextQuarterComparable();
Datetime startOfNextQuarter = Gmt.startOfThisCalendarQuarter().addMonths(3);
Assert.isFalse(nextQuarter.isGreaterThan(startOfNextQuarter.addMonths(-1)), 'One month before should not be greater than NEXT_QUARTER');
Assert.isFalse(nextQuarter.isGreaterThan(startOfNextQuarter), 'Start of next quarter should not be greater than itself');
Assert.isTrue(nextQuarter.isGreaterThan(startOfNextQuarter.addMonths(3).addDays(1)), 'One month after should be greater than NEXT_QUARTER');
}

@isTest
static void ensureIsLessThanOrEqualWorks() {
NextQuarterComparable nextQuarter = new NextQuarterComparable();
Datetime startOfNextQuarter = Gmt.startOfThisCalendarQuarter().addMonths(3);
Assert.isTrue(nextQuarter.isLessThanOrEqual(startOfNextQuarter.addMonths(-1)), 'One month before should be less than or equal to NEXT_QUARTER');
Assert.isTrue(nextQuarter.isLessThanOrEqual(startOfNextQuarter), 'Start of next quarter should be less than or equal to itself');
Assert.isFalse(nextQuarter.isLessThanOrEqual(startOfNextQuarter.addMonths(3)), 'Three months after should not be less than or equal to NEXT_QUARTER');
}

@isTest
static void ensuresIsGreaterThanOrEqualWorks() {
NextQuarterComparable nextQuarter = new NextQuarterComparable();
Datetime startOfNextQuarter = Gmt.startOfThisCalendarQuarter().addMonths(3);
Assert.isFalse(nextQuarter.isGreaterThanOrEqual(startOfNextQuarter.addMonths(-1)), 'One month before should not be greater than or equal to NEXT_QUARTER');
Assert.isTrue(nextQuarter.isGreaterThanOrEqual(startOfNextQuarter), 'Start of next quarter should be greater than or equal to itself');
Assert.isTrue(nextQuarter.isGreaterThanOrEqual(startOfNextQuarter.addMonths(3)), 'Three months after should be greater than or equal to NEXT_QUARTER');
}

@isTest
static void ensureIsNotEqualWorks() {
NextQuarterComparable nextQuarter = new NextQuarterComparable();
Datetime startOfNextQuarter = Gmt.startOfThisCalendarQuarter().addMonths(3);
Assert.isTrue(nextQuarter.isNotEqual(startOfNextQuarter.addMonths(-1)), 'One month before should not be equal to NEXT_QUARTER');
Assert.isFalse(nextQuarter.isNotEqual(startOfNextQuarter), 'Start of next quarter should be equal to itself');
Assert.isTrue(nextQuarter.isNotEqual(startOfNextQuarter.addMonths(3)), 'Three months after should not be equal to NEXT_QUARTER');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>62.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
Expand Up @@ -405,4 +405,17 @@ private class ParserTest {
}
Test.stopTest();
}

@isTest
static void ensuresParserCanParseNextQuarter() {
Parser p = new Parser();
String soqlQuery = 'SELECT Id FROM Opportunity WHERE CreatedDate = NEXT_QUARTER';
Test.startTest();
try {
p.parse(soqlQuery);
} catch(Exception e) {
Assert.fail('Expected no exception but got ' + e.getMessage() + ' for ' + soqlQuery);
}
Test.stopTest();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public with sharing class PrimitiveParserFactory {
Token.N_MONTHS_AGO_LITERAL => NMonthsAgoParser.class,
Token.THIS_QUARTER_LITERAL => ThisQuarterParser.class,
Token.LAST_QUARTER_LITERAL => LastQuarterParser.class,
Token.NEXT_QUARTER_LITERAL => NextQuarterParser.class,
Token.XTRUE => BooleanParser.class,
Token.XFALSE => BooleanParser.class,
Token.XNULL => NullParser.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
public with sharing class LastQuarterParser extends DateLiteralParser {
/**
* @description Parses the LAST_WEEK value from a query string.
* @description Parses the LAST_QUARTER value from a query string.
* @param query `String`
* @return `Intermediary`
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @description Parses the NEXT_QUARTER token
* @author Zackary Frazier
* @since 1/2/2025
*/
public with sharing class NextQuarterParser extends DateLiteralParser {
/**
* @description Parses the NEXT_QUARTER value from a query string.
* @param query `String`
* @return `Intermediary`
*/
public override Intermediary parse(String query) {
return parse(query, Token.NEXT_QUARTER_LITERAL);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>62.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@isTest
private class NextQuarterParserTest {

@isTest
static void ensureNextQuarterCanBeParsed() {
NextQuarterParser parser = new NextQuarterParser();

Test.startTest();
Intermediary intermediary = parser.parse('NEXT_QUARTER');
Test.stopTest();

Assert.areEqual('', intermediary.subquery, 'Subquery should be empty');
Node head = intermediary.head;
Assert.areEqual(head.id, Token.NEXT_QUARTER_LITERAL, 'Id should be LAST_QUARTER_LITERAL');
Assert.areEqual(head.nodeType, NodeType.DATE_LITERAL, 'Node type should be DATE_LITERAL');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>62.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,5 @@ public inherited sharing class Token {
public final static String N_MONTHS_AGO_LITERAL = 'n_months_ago';
public final static String THIS_QUARTER_LITERAL = 'this_quarter';
public final static String LAST_QUARTER_LITERAL = 'last_quarter';
public final static String NEXT_QUARTER_LITERAL = 'next_quarter';
}
Loading