fix(timeRangeSelector): Allow selecting today's UTC date
With UTC enabled, the absolute date range picker still capped the calendar at the local `new Date()`. When the local date was a day behind UTC, today's UTC date was disabled and could not be picked. Convert the max date with `getUtcToSystem` when `utc` is set, the same conversion the selector already applies to the start and end dates.
This commit is contained in:
1 parent
6909f35d48
commit
f21570224e
2 files changed
+37
-1
No files matched your search
@@ -0,0 +1,35 @@
|
||||
import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
|
||||
import {resetMockDate, setMockDate} from 'sentry-test/utils';
|
||||
|
||||
import {DateRange} from 'sentry/components/timeRangeSelector/dateRange';
|
||||
|
||||
jest.unmock('react-date-range');
|
||||
|
||||
describe('DateRange', () => {
|
||||
afterEach(() => {
|
||||
resetMockDate();
|
||||
});
|
||||
|
||||
it("can select today's UTC date while the local date is still the day before", async () => {
|
||||
// 22:00 on Oct 16 in America/New_York, already Oct 17 in UTC
|
||||
setMockDate(new Date('2017-10-17T02:00:00Z'));
|
||||
const onChange = jest.fn();
|
||||
|
||||
render(
|
||||
<DateRange
|
||||
utc
|
||||
start={new Date('2017-10-10T00:00:00')}
|
||||
end={new Date('2017-10-16T23:59:59')}
|
||||
onChange={onChange}
|
||||
onChangeUtc={jest.fn()}
|
||||
/>
|
||||
);
|
||||
|
||||
await userEvent.click(await screen.findByRole('button', {name: '17'}));
|
||||
|
||||
expect(onChange).toHaveBeenCalledWith({
|
||||
start: new Date('2017-10-17T00:00:00'),
|
||||
end: new Date('2017-10-17T23:59:59'),
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -16,6 +16,7 @@ import {trackAnalytics} from 'sentry/utils/analytics';
|
||||
import {
|
||||
getEndOfDay,
|
||||
getStartOfPeriodAgo,
|
||||
getUtcToSystem,
|
||||
isValidTime,
|
||||
setDateToTime,
|
||||
} from 'sentry/utils/dates';
|
||||
@@ -195,7 +196,7 @@ class BaseDateRange extends Component<Props, State> {
|
||||
// (or really, Jan 2 @ 00:00:00 - 1 second), while the start time is at 00:00
|
||||
let minDate = getStartOfPeriodAgo('days', (maxPickableDays ?? MAX_PICKABLE_DAYS) - 1);
|
||||
|
||||
let maxDate = new Date();
|
||||
let maxDate = utc ? getUtcToSystem(new Date()) : new Date();
|
||||
|
||||
// if the start and end date are the same, it means the user can still select another date,
|
||||
// at this point we want to apply the maxDateRange
|
||||
|
||||
Reference in new issue
Block a user