mirror of
https://github.com/datahub-project/datahub.git
synced 2025-12-02 21:54:07 +00:00
fix(UI): incorrect month showing in MAU (#11918)
This commit is contained in:
parent
970453e584
commit
e7e208fdfe
@ -84,8 +84,21 @@ public final class GetChartsResolver implements DataFetcher<List<AnalyticsChartG
|
|||||||
final DateTime end,
|
final DateTime end,
|
||||||
final String title,
|
final String title,
|
||||||
final DateInterval interval) {
|
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 =
|
final List<NamedLine> timeSeriesLines =
|
||||||
_analyticsService.getTimeseriesChart(
|
_analyticsService.getTimeseriesChart(
|
||||||
@ -96,6 +109,7 @@ public final class GetChartsResolver implements DataFetcher<List<AnalyticsChartG
|
|||||||
ImmutableMap.of(),
|
ImmutableMap.of(),
|
||||||
Collections.emptyMap(),
|
Collections.emptyMap(),
|
||||||
Optional.of("browserId"));
|
Optional.of("browserId"));
|
||||||
|
|
||||||
return TimeSeriesChart.builder()
|
return TimeSeriesChart.builder()
|
||||||
.setTitle(title)
|
.setTitle(title)
|
||||||
.setDateRange(dateRange)
|
.setDateRange(dateRange)
|
||||||
|
|||||||
@ -47,4 +47,26 @@ public class DateUtilTest {
|
|||||||
Mockito.when(dateUtil.getNow()).thenReturn(setTimeParts(8, false));
|
Mockito.when(dateUtil.getNow()).thenReturn(setTimeParts(8, false));
|
||||||
assertEqualStartOfNextWeek(dateUtil, 9);
|
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…
x
Reference in New Issue
Block a user