Skip to content

Commit

Permalink
[Tech Debt] Fix off-by-one error in previous year calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
levinmr committed Feb 24, 2025
1 parent b3800ed commit 6d1e0f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/google_analytics/query_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,16 @@ function _mapStringToDateRange(rangeString) {
);
const daysSinceStartOfPreviousYear =
differenceInDays(startOfCurrentYear(), startOfPreviousYear()) +
daysSinceStartOfCurrentYear;
daysSinceStartOfCurrentYear -
1;
const daysSinceStartOfCurrentFiscalYear = differenceInDays(
today(),
startOfCurrentFiscalYear(),
);
const daysSinceStartOfPreviousFiscalYear =
differenceInDays(startOfCurrentFiscalYear(), startOfPreviousFiscalYear()) +
daysSinceStartOfCurrentFiscalYear;
daysSinceStartOfCurrentFiscalYear -
1;
const descriptorToDateRangeHashMap = {
yesterday: { startDate: "yesterday", endDate: "yesterday" },
"7-days": { startDate: "7daysAgo", endDate: "yesterday" },
Expand Down
8 changes: 4 additions & 4 deletions test/google_analytics/query_builder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ describe("GoogleAnalyticsQueryBuilder", () => {
},
{
endDate: "49daysAgo",
startDate: "415daysAgo",
startDate: "414daysAgo",
},
{
endDate: "141daysAgo",
startDate: "507daysAgo",
startDate: "506daysAgo",
},
],
},
Expand Down Expand Up @@ -168,11 +168,11 @@ describe("GoogleAnalyticsQueryBuilder", () => {
},
{
endDate: "291daysAgo",
startDate: "657daysAgo",
startDate: "656daysAgo",
},
{
endDate: "18daysAgo",
startDate: "383daysAgo",
startDate: "382daysAgo",
},
],
},
Expand Down

0 comments on commit 6d1e0f4

Please sign in to comment.