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
5 changes: 2 additions & 3 deletions moxygen/main/default/classes/database/MockDatabaseTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -5798,12 +5798,11 @@ private class MockDatabaseTest {
@isTest
static void ensureLastQuarterInWhereClause() {
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)
CloseDate = Gmt.today().addMonths(-i)
)
);
}
Expand Down Expand Up @@ -5868,7 +5867,7 @@ private class MockDatabaseTest {

Test.startTest();
List<Opportunity> opportunities = MockDatabase.query(
'SELECT Id FROM Opportunity WHERE CloseDate = NEXT_N_QUARTERS:2'
'SELECT Id, Name, CloseDate FROM Opportunity WHERE CloseDate = NEXT_N_QUARTERS:2'
);
Test.stopTest();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,13 @@
*/
public with sharing class LastNQuartersComparable extends DateLiteralComparable {
public override Boolean isLessThan(Datetime fieldValue) {
Datetime thisCalendarQuarter = Datetime.newInstanceGmt(
Gmt.today().year(),
Math.mod((Integer) Math.ceil(Gmt.today().month() / 3), 4) + 1,
1
);
Datetime thisCalendarQuarter = Gmt.startOfThisCalendarQuarter();
Datetime startingQuarter = thisCalendarQuarter.addMonths(-3 * this.n);
return fieldValue < startingQuarter;
}

public override Boolean isGreaterThan(Datetime fieldValue) {
Datetime thisCalendarQuarter = Datetime.newInstanceGmt(
Gmt.today().year(),
Math.mod((Integer) Math.ceil(Gmt.today().month() / 3), 4) + 1,
1
);
Datetime thisCalendarQuarter = Gmt.startOfThisCalendarQuarter();
return fieldValue >= thisCalendarQuarter;
}
}
19 changes: 14 additions & 5 deletions moxygen/main/default/classes/utilities/gmt/GMT.cls
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,20 @@ public with sharing class GMT {
* @return `Date`
*/
public static Datetime startOfThisCalendarQuarter() {
return Datetime.newInstanceGmt(
Gmt.today().year(),
Math.mod(Gmt.today().month() - (Gmt.today().month() - 1), 3),
1
);
Datetime today = Gmt.today();
Integer startMonth = today.month();

if (startMonth >= 10) {
startMonth = 10;
} else if (startMonth >= 7) {
startMonth = 7;
} else if (startMonth >= 4) {
startMonth = 4;
} else {
startMonth = 1;
}

return Datetime.newInstanceGmt(today.year(), startMonth, 1);
}

/**
Expand Down