Repository navigation
fix: incorrect timestamp timezone conversion and relative time preview #40420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
99b22b1
chore: add field hint to timezone in timestamp picker
abhinavkrin f772862
add snapshot
abhinavkrin 38d85ba
chore: rearrange timestamp picker fields and improve terminology
abhinavkrin 063f320
chore: fix grammar
abhinavkrin c9982e9
fix: incorrect timestamp timezone conversion and relative time preview
abhinavkrin 34a5ba6
added changeset
abhinavkrin 483356e
fix
abhinavkrin 22e248e
Merge branch 'develop' into chore/add-field-hint--to-timezone-picker
abhinavkrin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@rocket.chat/gazzodown': patch | ||
| '@rocket.chat/i18n': patch | ||
| '@rocket.chat/meteor': patch | ||
| --- | ||
|
|
||
| Fixes Insert Timestamp relative time preview not updating on input changes and losing the user's locale after the first refresh tick. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
packages/gazzodown/src/elements/Timestamp/RelativeTime.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import { render, screen, act } from '@testing-library/react'; | ||
|
|
||
| import TimestampWrapper from './index'; | ||
| import { MarkupInteractionContext } from '../../MarkupInteractionContext'; | ||
|
|
||
| beforeEach(() => { | ||
| jest.useFakeTimers(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| jest.useRealTimers(); | ||
| }); | ||
|
|
||
| const makeTimestampNode = (epochSeconds: number) => | ||
| ({ | ||
| type: 'TIMESTAMP' as const, | ||
| value: { | ||
| timestamp: String(epochSeconds), | ||
| format: 'R' as const, | ||
| }, | ||
| }) satisfies Parameters<typeof TimestampWrapper>[0]['children']; | ||
|
|
||
| it('should update displayed text immediately when the value prop changes', () => { | ||
| const now = new Date('2026-05-12T12:00:00.000Z'); | ||
| jest.setSystemTime(now); | ||
|
|
||
| const futureA = Math.floor(now.getTime() / 1000) + 7200; | ||
| const futureB = Math.floor(now.getTime() / 1000) + 86400; | ||
|
|
||
| const { rerender } = render(<TimestampWrapper>{makeTimestampNode(futureA)}</TimestampWrapper>); | ||
|
|
||
| const tagA = screen.getByText(/2 hours/i); | ||
| expect(tagA).toBeInTheDocument(); | ||
|
|
||
| rerender(<TimestampWrapper>{makeTimestampNode(futureB)}</TimestampWrapper>); | ||
|
|
||
| const tagB = screen.getByText(/tomorrow/i); | ||
| expect(tagB).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should preserve the locale from context after interval refresh', () => { | ||
| const now = new Date('2026-05-12T12:00:00.000Z'); | ||
| jest.setSystemTime(now); | ||
|
|
||
| const futureEpoch = Math.floor(now.getTime() / 1000) + 30; | ||
|
|
||
| render( | ||
| <MarkupInteractionContext.Provider value={{ language: 'de' }}> | ||
| <TimestampWrapper>{makeTimestampNode(futureEpoch)}</TimestampWrapper> | ||
| </MarkupInteractionContext.Provider>, | ||
| ); | ||
|
|
||
| const initial = screen.getByRole('time'); | ||
| const initialText = initial.textContent; | ||
| expect(initialText).toBeTruthy(); | ||
|
|
||
| act(() => { | ||
| jest.advanceTimersByTime(1500); | ||
| }); | ||
|
|
||
| const afterTick = screen.getByRole('time'); | ||
| const afterTickText = afterTick.textContent; | ||
| expect(afterTickText).toBeTruthy(); | ||
|
|
||
| expect(afterTickText).not.toMatch(/seconds/i); | ||
| }); | ||
|
|
||
| it('should update displayed text immediately when locale changes via context', () => { | ||
| const now = new Date('2026-05-12T12:00:00.000Z'); | ||
| jest.setSystemTime(now); | ||
|
|
||
| const futureEpoch = Math.floor(now.getTime() / 1000) + 30; | ||
|
|
||
| const { rerender } = render( | ||
| <MarkupInteractionContext.Provider value={{ language: 'en' }}> | ||
| <TimestampWrapper>{makeTimestampNode(futureEpoch)}</TimestampWrapper> | ||
| </MarkupInteractionContext.Provider>, | ||
| ); | ||
|
|
||
| expect(screen.getByRole('time').textContent).toMatch(/seconds/i); | ||
|
|
||
| rerender( | ||
| <MarkupInteractionContext.Provider value={{ language: 'de' }}> | ||
| <TimestampWrapper>{makeTimestampNode(futureEpoch)}</TimestampWrapper> | ||
| </MarkupInteractionContext.Provider>, | ||
| ); | ||
|
|
||
| expect(screen.getByRole('time').textContent).not.toMatch(/seconds/i); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.