Update quarter end date logic

This commit is contained in:
Brenda Sukh
2020-12-04 10:18:17 -05:00
parent 15710d8a17
commit c81456a175
2 changed files with 12 additions and 6 deletions
@@ -73,8 +73,9 @@ describe('<PeriodSelect />', () => {
it(`Should select ${duration}`, async () => {
const mockOnSelect = jest.fn();
const mockAggregation =
// Can't select an option that's already the default
DefaultPageFilters.duration === duration
? Duration.P1M
? Duration.P30D
: DefaultPageFilters.duration;
const rendered = await renderInTestApp(
@@ -88,7 +89,6 @@ describe('<PeriodSelect />', () => {
const button = getByRole(periodSelect, 'button');
UserEvent.click(button);
await waitFor(() => rendered.getByText('Past 60 Days'));
UserEvent.click(rendered.getByTestId(`period-select-option-${duration}`));
expect(mockOnSelect).toHaveBeenLastCalledWith(duration);
});
+10 -4
View File
@@ -60,10 +60,7 @@ export function exclusiveEndDateOf(
.add(1, 'day')
.format(DEFAULT_DATE_FORMAT);
case Duration.P3M:
return moment(inclusiveEndDate)
.utc()
.startOf('quarter')
.format(DEFAULT_DATE_FORMAT);
return quarterEndDate(inclusiveEndDate);
default:
return assertNever(duration);
}
@@ -83,3 +80,12 @@ export function inclusiveEndDateOf(
export function intervalsOf(duration: Duration, inclusiveEndDate: string) {
return `R2/${duration}/${exclusiveEndDateOf(duration, inclusiveEndDate)}`;
}
function quarterEndDate(inclusiveEndDate: string): string {
const endDate = moment(inclusiveEndDate).utc();
const endOfQuarter = endDate.endOf('quarter').format(DEFAULT_DATE_FORMAT);
if (endOfQuarter === inclusiveEndDate) {
return inclusiveEndDate;
}
return endDate.startOf('quarter').format(DEFAULT_DATE_FORMAT);
}