diff --git a/static/app/components/timeSince.spec.tsx b/static/app/components/timeSince.spec.tsx index 6a3cffaf963f94..191e1fd5cb7fec 100644 --- a/static/app/components/timeSince.spec.tsx +++ b/static/app/components/timeSince.spec.tsx @@ -1,6 +1,7 @@ -import {render, screen} from 'sentry-test/reactTestingLibrary'; +import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary'; import TimeSince from 'sentry/components/timeSince'; +import {TimezoneProvider} from 'sentry/components/timezoneProvider'; describe('TimeSince', () => { const now = new Date(); @@ -56,4 +57,18 @@ describe('TimeSince', () => { render(); expect(screen.getByText('10m atrás')).toBeInTheDocument(); }); + + it('respects timezone in tooltip', async () => { + const date = new Date('2024-01-15T12:00:00Z'); + render( + + + + ); + const timeElement = screen.getByRole('time'); + await userEvent.hover(timeElement); + await waitFor(() => { + expect(screen.getByText(/EST/)).toBeInTheDocument(); + }); + }); }); diff --git a/static/app/components/timeSince.tsx b/static/app/components/timeSince.tsx index 7489ce0e14dab8..6826ad2a37ce49 100644 --- a/static/app/components/timeSince.tsx +++ b/static/app/components/timeSince.tsx @@ -9,6 +9,8 @@ import getDuration from 'sentry/utils/duration/getDuration'; import type {ColorOrAlias} from 'sentry/utils/theme'; import {useUser} from 'sentry/utils/useUser'; +import {useTimezone} from './timezoneProvider'; + function getDateObj(date: RelaxedDateType): Date { return typeof date === 'string' || isNumber(date) ? new Date(date) : date; } @@ -120,6 +122,7 @@ function TimeSince({ ...props }: Props) { const user = useUser(); + const tz = useTimezone(); // Counter to trigger periodic re-computation of relative time const [tick, setTick] = useState(0); @@ -153,7 +156,7 @@ function TimeSince({ : 'MMMM D, YYYY h:mm A z'; const format = options?.clock24Hours ? 'MMMM D, YYYY HH:mm z' : tooltipFormat; - const tooltip = moment(dateObj).format(format); + const tooltip = moment.tz(dateObj, tz).format(format); return (