-
Notifications
You must be signed in to change notification settings - Fork 274
[WS-2756] Localise football match kick off time in Sport Header #14093
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
Louis-Matsika
merged 10 commits into
latest
from
WS-2756-localise-sport-header-times-temporal
Jun 10, 2026
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1c0dfb2
Initial commit
hotinglok 28d69a5
Use state to prevent hydration errors
hotinglok 49f3a7c
Use latin numerals, minor refactoring
hotinglok f5a51a9
Remove console.logs and add tests
hotinglok 00a4e3e
Merge branch 'latest' into WS-2756-localise-sport-header-times-temporal
hotinglok b4ef70f
Update import
hotinglok e12b6d4
Revert "Update import"
hotinglok 76f7c8a
Add temporal-polyfill import
hotinglok c0bbbd3
Update yarn.lock
hotinglok 12fd026
Merge branch 'latest' into WS-2756-localise-sport-header-times-temporal
Louis-Matsika 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
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
29 changes: 21 additions & 8 deletions
29
src/app/components-webcore/SportDataHeader/head-to-head-v2/components/fixture-time.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 |
|---|---|---|
| @@ -1,22 +1,35 @@ | ||
| import { useEffect, useState } from 'react'; | ||
| import VisuallyHiddenText from '../../../../components/VisuallyHiddenText'; | ||
| import styles from '../index.styles'; | ||
| import getLocalisedTime from '../helpers/localise-time'; | ||
|
|
||
| interface TimeData { | ||
| displayTimeUK: string; | ||
| accessibleTime: string; | ||
| } | ||
|
|
||
| interface TimeProps { | ||
| date: string; | ||
| time: TimeData; | ||
| } | ||
|
|
||
| const Time = ({ time }: TimeProps) => ( | ||
| <> | ||
| <time css={styles.fixtureTime} aria-hidden="true"> | ||
| {time.displayTimeUK} | ||
| </time> | ||
| <VisuallyHiddenText>{time.accessibleTime}</VisuallyHiddenText> | ||
| </> | ||
| ); | ||
| const Time = ({ date, time }: TimeProps) => { | ||
| const [localisedTime, setLocalisedTime] = useState(time.displayTimeUK); | ||
|
|
||
| useEffect(() => { | ||
| const clientTime = getLocalisedTime(date, time.displayTimeUK); | ||
| setLocalisedTime(clientTime); | ||
| }, []); | ||
|
Check warning on line 22 in src/app/components-webcore/SportDataHeader/head-to-head-v2/components/fixture-time.tsx
|
||
|
|
||
| return ( | ||
| <> | ||
| <time css={styles.fixtureTime} aria-hidden="true"> | ||
| {localisedTime} | ||
| </time> | ||
|
|
||
| <VisuallyHiddenText>{localisedTime}</VisuallyHiddenText> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| export default Time; | ||
44 changes: 44 additions & 0 deletions
44
src/app/components-webcore/SportDataHeader/head-to-head-v2/helpers/localise-time.ts
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,44 @@ | ||
| import 'temporal-polyfill/global'; | ||
|
|
||
| const getLocalisedTime = (inputDate, inputTime) => { | ||
| const [, day, monthName, year] = inputDate.split(' '); | ||
| const [hour, minute] = inputTime.split(':').map(Number); | ||
|
|
||
| const monthIndex = | ||
| [ | ||
| 'Jan', | ||
| 'Feb', | ||
| 'Mar', | ||
| 'Apr', | ||
| 'May', | ||
| 'Jun', | ||
| 'Jul', | ||
| 'Aug', | ||
| 'Sep', | ||
| 'Oct', | ||
| 'Nov', | ||
| 'Dec', | ||
| ].indexOf(monthName) + 1; | ||
|
|
||
| const ukDateTime = Temporal.ZonedDateTime.from({ | ||
| timeZone: 'Europe/London', | ||
| year: Number(year), | ||
| month: monthIndex, | ||
| day: Number(day), | ||
| hour, | ||
| minute, | ||
| }); | ||
|
|
||
| const userLocalDateTime = ukDateTime | ||
| .withTimeZone(Temporal.Now.timeZoneId()) | ||
| .toLocaleString(undefined, { | ||
| hour: '2-digit', | ||
| minute: '2-digit', | ||
| hour12: false, | ||
| numberingSystem: 'latn', | ||
| }); | ||
|
|
||
| return userLocalDateTime; | ||
| }; | ||
|
|
||
| export default getLocalisedTime; |
77 changes: 77 additions & 0 deletions
77
src/app/components-webcore/SportDataHeader/head-to-head-v2/tests/helpers/index.test.ts
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,77 @@ | ||
| import 'temporal-polyfill/global'; | ||
| import getLocalisedTime from '../../helpers/localise-time'; | ||
|
|
||
| describe('getLocalisedTime', () => { | ||
| const originalTimeZoneId = Temporal.Now.timeZoneId; | ||
|
|
||
| afterEach(() => { | ||
| Temporal.Now.timeZoneId = originalTimeZoneId; | ||
| }); | ||
|
|
||
| it('should return the same time when user is in UK timezone', () => { | ||
| Temporal.Now.timeZoneId = () => 'Europe/London'; | ||
|
|
||
| const result = getLocalisedTime('Sat 15 Jun 2024', '15:00'); | ||
| expect(result).toBe('15:00'); | ||
| }); | ||
|
|
||
| it('should convert UK time to CET timezone (1 hour ahead in summer)', () => { | ||
| Temporal.Now.timeZoneId = () => 'Europe/Paris'; | ||
|
|
||
| const result = getLocalisedTime('Sat 15 Jun 2024', '15:00'); | ||
| expect(result).toBe('16:00'); | ||
| }); | ||
|
|
||
| it('should convert UK time to EST timezone (5 hours behind in summer)', () => { | ||
| Temporal.Now.timeZoneId = () => 'America/New_York'; | ||
|
|
||
| const result = getLocalisedTime('Sat 15 Jun 2024', '15:00'); | ||
| expect(result).toBe('10:00'); | ||
| }); | ||
|
|
||
| it('should handle midnight correctly', () => { | ||
| Temporal.Now.timeZoneId = () => 'Europe/London'; | ||
|
|
||
| const result = getLocalisedTime('Mon 1 Jan 2024', '00:00'); | ||
| expect(result).toBe('00:00'); | ||
| }); | ||
|
|
||
| it('should handle day transition when converting to later timezone', () => { | ||
| Temporal.Now.timeZoneId = () => 'Asia/Tokyo'; | ||
|
|
||
| const result = getLocalisedTime('Sat 15 Jun 2024', '20:00'); | ||
| expect(result).toBe('04:00'); | ||
| }); | ||
|
|
||
| it('should parse all months correctly', () => { | ||
| Temporal.Now.timeZoneId = () => 'Europe/London'; | ||
|
|
||
| const months = [ | ||
| 'Jan', | ||
| 'Feb', | ||
| 'Mar', | ||
| 'Apr', | ||
| 'May', | ||
| 'Jun', | ||
| 'Jul', | ||
| 'Aug', | ||
| 'Sep', | ||
| 'Oct', | ||
| 'Nov', | ||
| 'Dec', | ||
| ]; | ||
|
|
||
| months.forEach((month, index) => { | ||
| const day = index + 1; | ||
| const result = getLocalisedTime(`Mon ${day} ${month} 2024`, '12:00'); | ||
| expect(result).toBe('12:00'); | ||
| }); | ||
| }); | ||
|
|
||
| it('should handle winter time correctly with GMT offset', () => { | ||
| Temporal.Now.timeZoneId = () => 'Europe/Paris'; | ||
|
|
||
| const result = getLocalisedTime('Sat 15 Jan 2024', '15:00'); | ||
| expect(result).toBe('16:00'); | ||
| }); | ||
| }); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Github crying about eof