Skip to content

Commit e13a217

Browse files
authored
Refactor MockDatabaseTest and LastNFiscalQuartersComparable to use Gmt.startOfThisFiscalQuarter for improved accuracy in date handling and assertions in tests (#313)
1 parent 735289b commit e13a217

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

moxygen/main/default/classes/database/MockDatabaseTest.cls

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7149,12 +7149,12 @@ private class MockDatabaseTest {
71497149
@isTest
71507150
static void ensureLasNFiscalQuartersWorksInWhereClause() {
71517151
List<Opportunity> oppList = new List<Opportunity>();
7152-
Date startOfYear = Date.newInstance(Gmt.today().year(), 1, 1);
7152+
Date startOfThisFiscalQuarter = Gmt.startOfThisFiscalQuarter();
71537153
for (Integer i = 0; i < 36; i++) {
71547154
oppList.add(
71557155
new Opportunity(
71567156
Name = 'Opp' + i,
7157-
CloseDate = startOfYear.addMonths(-i)
7157+
CloseDate = startOfThisFiscalQuarter.addMonths(-i)
71587158
)
71597159
);
71607160
}
@@ -7168,12 +7168,11 @@ private class MockDatabaseTest {
71687168
Test.stopTest();
71697169

71707170
Assert.areEqual(
7171-
3,
7171+
6,
71727172
opportunities.size(),
71737173
'Incorrect number of opportunities'
71747174
);
71757175

7176-
Date startOfThisFiscalQuarter = Gmt.startOfThisFiscalQuarter();
71777176
Date startDate = startOfThisFiscalQuarter.addMonths(-6);
71787177
for (Opportunity opp : opportunities) {
71797178
Assert.isTrue(

moxygen/main/default/classes/database/soql-engine/interpreter/operator-handler/date-literal-comparable/LastNFiscalQuartersComparable.cls

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ public with sharing class LastNFiscalQuartersComparable extends DateLiteralCompa
1414
}
1515

1616
public override Boolean isGreaterThan(Datetime fieldValue) {
17-
Integer nMonthsAgo = this.n * 3;
18-
// Does NOT include the current quarter, thus the -3
19-
Date nFiscalQuartersAgo = Gmt.startOfthisFiscalQuarter()
20-
.addMonths(-nMonthsAgo);
21-
return fieldValue >= nFiscalQuartersAgo.addMonths(3);
17+
// For LAST_N_FISCAL_QUARTERS, isGreaterThan should return true
18+
// when fieldValue is >= the start of the current fiscal quarter
19+
return fieldValue >= Gmt.startOfthisFiscalQuarter();
2220
}
2321
}

0 commit comments

Comments
 (0)