Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion static/app/components/timeSince.spec.tsx
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -56,4 +57,18 @@ describe('TimeSince', () => {
render(<TimeSince unitStyle="extraShort" date={pastTenMin} suffix="atrás" />);
expect(screen.getByText('10m atrás')).toBeInTheDocument();
});

it('respects timezone in tooltip', async () => {
const date = new Date('2024-01-15T12:00:00Z');
render(
<TimezoneProvider timezone="America/New_York">
<TimeSince date={date} />
</TimezoneProvider>
);
const timeElement = screen.getByRole('time');
await userEvent.hover(timeElement);
await waitFor(() => {
expect(screen.getByText(/EST/)).toBeInTheDocument();
});
});
});
5 changes: 4 additions & 1 deletion static/app/components/timeSince.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 (
<Tooltip
Expand Down
Loading