diff --git a/static/app/components/timeRangeSelector/dateRange.spec.tsx b/static/app/components/timeRangeSelector/dateRange.spec.tsx new file mode 100644 index 0000000..6cde320 --- /dev/null +++ b/static/app/components/timeRangeSelector/dateRange.spec.tsx @@ -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( + + ); + + 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'), + }); + }); +}); diff --git a/static/app/components/timeRangeSelector/dateRange.tsx b/static/app/components/timeRangeSelector/dateRange.tsx index 4e53b2c..425cf0a 100644 --- a/static/app/components/timeRangeSelector/dateRange.tsx +++ b/static/app/components/timeRangeSelector/dateRange.tsx @@ -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 { // (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