Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(UI): incorrect month showing in MAU #11918

Merged
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 @@ -84,8 +84,21 @@ private TimeSeriesChart getActiveUsersTimeSeriesChart(
final DateTime end,
final String title,
final DateInterval interval) {
final DateRange dateRange =
new DateRange(String.valueOf(beginning.getMillis()), String.valueOf(end.getMillis()));

final DateRange dateRange;

// adjust month to show 1st of month rather than last day of previous month
if (interval == DateInterval.MONTH) {
dateRange =
new DateRange(
String.valueOf(beginning.plusDays(1).getMillis()), // Shift start by 1 day
String.valueOf(end.plusDays(1).getMillis()) // Shift end by 1 day
);
} else {
// week display starting Sundays
dateRange =
new DateRange(String.valueOf(beginning.getMillis()), String.valueOf(end.getMillis()));
}

final List<NamedLine> timeSeriesLines =
_analyticsService.getTimeseriesChart(
Expand All @@ -96,6 +109,7 @@ private TimeSeriesChart getActiveUsersTimeSeriesChart(
ImmutableMap.of(),
Collections.emptyMap(),
Optional.of("browserId"));

return TimeSeriesChart.builder()
.setTitle(title)
.setDateRange(dateRange)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,26 @@ public void testStartOfNextWeek() {
Mockito.when(dateUtil.getNow()).thenReturn(setTimeParts(8, false));
assertEqualStartOfNextWeek(dateUtil, 9);
}

// validates logic to display correct dates in MAU chart
@Test
public void testDateAdjustmentsForMonth() {
DateUtil dateUtil = Mockito.spy(DateUtil.class);

Mockito.when(dateUtil.getNow()).thenReturn(new DateTime(2024, 11, 15, 0, 0, 0));

// start date should be next month minus a day
// but we want to display Dec 1 instead of Nov 30, so add a day and verify it's Dec
DateTime startOfNextMonthMinus12 = dateUtil.getStartOfNextMonth().minusMonths(12);
DateTime adjustedStart = startOfNextMonthMinus12.minusMillis(1).plusDays(1);
assertEquals(12, adjustedStart.getMonthOfYear()); // Verify it is December
assertEquals(2023, adjustedStart.getYear()); // Verify it is 2023

// verify that the end date displays correctly
// the chart will display Oct 1 as the last month because we don't show current month
DateTime startOfThisMonth = dateUtil.getStartOfThisMonth();
DateTime adjustedEnd = startOfThisMonth.minusMillis(1).plusDays(1);
assertEquals(11, adjustedEnd.getMonthOfYear()); // Verify it is November
assertEquals(2024, adjustedEnd.getYear()); // Verify it is 2024
}
}
Loading