Skip to content

Commit 35ce7bb

Browse files
committedFeb 26, 2025··
[Tech Debt] Really fix off-by-one error in yearly calculations
1 parent 607e1fa commit 35ce7bb

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed
 

‎src/google_analytics/query_builder.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,14 @@ function _mapStringToDateRange(rangeString) {
6262
);
6363
const daysSinceStartOfPreviousYear =
6464
differenceInDays(startOfCurrentYear(), startOfPreviousYear()) +
65-
daysSinceStartOfCurrentYear -
66-
1;
65+
daysSinceStartOfCurrentYear;
6766
const daysSinceStartOfCurrentFiscalYear = differenceInDays(
6867
today(),
6968
startOfCurrentFiscalYear(),
7069
);
7170
const daysSinceStartOfPreviousFiscalYear =
7271
differenceInDays(startOfCurrentFiscalYear(), startOfPreviousFiscalYear()) +
73-
daysSinceStartOfCurrentFiscalYear -
74-
1;
72+
daysSinceStartOfCurrentFiscalYear;
7573
const descriptorToDateRangeHashMap = {
7674
yesterday: { startDate: "yesterday", endDate: "yesterday" },
7775
"7-days": { startDate: "7daysAgo", endDate: "yesterday" },
@@ -87,11 +85,11 @@ function _mapStringToDateRange(rangeString) {
8785
},
8886
"previous-year": {
8987
startDate: `${daysSinceStartOfPreviousYear}daysAgo`,
90-
endDate: `${daysSinceStartOfCurrentYear}daysAgo`,
88+
endDate: `${daysSinceStartOfCurrentYear + 1}daysAgo`,
9189
},
9290
"previous-fiscal-year": {
9391
startDate: `${daysSinceStartOfPreviousFiscalYear}daysAgo`,
94-
endDate: `${daysSinceStartOfCurrentFiscalYear}daysAgo`,
92+
endDate: `${daysSinceStartOfCurrentFiscalYear + 1}daysAgo`,
9593
},
9694
};
9795

‎test/google_analytics/query_builder.test.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,20 @@ describe("GoogleAnalyticsQueryBuilder", () => {
7474
property: `properties/${appConfig.account.ids}`,
7575
dateRanges: [
7676
{
77-
endDate: "yesterday",
78-
startDate: "49daysAgo",
77+
endDate: "yesterday", // 2/18/2025
78+
startDate: "49daysAgo", // 1/1/2025
7979
},
8080
{
81-
endDate: "yesterday",
82-
startDate: "141daysAgo",
81+
endDate: "yesterday", // 2/18/2025
82+
startDate: "141daysAgo", // 10/1/2024
8383
},
8484
{
85-
endDate: "49daysAgo",
86-
startDate: "414daysAgo",
85+
endDate: "50daysAgo", // 12/31/2024
86+
startDate: "415daysAgo", // 1/1/2024
8787
},
8888
{
89-
endDate: "141daysAgo",
90-
startDate: "506daysAgo",
89+
endDate: "142daysAgo", // 9/30/2024
90+
startDate: "507daysAgo", // 10/1/2023
9191
},
9292
],
9393
},
@@ -159,20 +159,20 @@ describe("GoogleAnalyticsQueryBuilder", () => {
159159
property: `properties/${appConfig.account.ids}`,
160160
dateRanges: [
161161
{
162-
endDate: "yesterday",
163-
startDate: "291daysAgo",
162+
endDate: "yesterday", // 10/18/2025
163+
startDate: "291daysAgo", // 1/1/2025
164164
},
165165
{
166-
endDate: "yesterday",
167-
startDate: "18daysAgo",
166+
endDate: "yesterday", // 10/18/2025
167+
startDate: "18daysAgo", // 10/1/2025
168168
},
169169
{
170-
endDate: "291daysAgo",
171-
startDate: "656daysAgo",
170+
endDate: "292daysAgo", // 12/31/2024
171+
startDate: "657daysAgo", // 1/1/2024
172172
},
173173
{
174-
endDate: "18daysAgo",
175-
startDate: "382daysAgo",
174+
endDate: "19daysAgo", // 9/30/2025
175+
startDate: "383daysAgo", // 10/1/2024
176176
},
177177
],
178178
},

0 commit comments

Comments
 (0)
Please sign in to comment.