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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"react-dom": "19.2.6",
"react-helmet": "6.1.0",
"react-lazyload": "3.2.1",
"temporal-polyfill": "0.3.0",
"undici": "8.3.0",
"uuid": "13.0.1",
"winston": "patch:winston@3.8.2#./patches/winston-file-descriptor.patch"
Expand Down Expand Up @@ -184,4 +185,4 @@
]
},
"packageManager": "yarn@4.9.4"
}
}

@HarveyPeachey HarveyPeachey Jun 9, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github crying about eof

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const Centre = ({ data, maxScoreLength }: CentreProps) => {
{shouldShowScores(status) ? (
<Played data={data} />
) : (
<Time time={data.time} />
<Time date={data.date} time={data.time} />
)}
</div>
);
Expand Down
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

View workflow job for this annotation

GitHub Actions / build (22.x)

React Hook useEffect has missing dependencies: 'date' and 'time.displayTimeUK'. Either include them or remove the dependency array

return (
<>
<time css={styles.fixtureTime} aria-hidden="true">
{localisedTime}
</time>

<VisuallyHiddenText>{localisedTime}</VisuallyHiddenText>
</>
);
};

export default Time;
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;
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');
});
});
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15866,6 +15866,7 @@ __metadata:
retry: "npm:0.13.1"
storybook: "npm:10.3.6"
supertest: "npm:7.2.2"
temporal-polyfill: "npm:0.3.0"
timemachine: "npm:0.3.2"
ts-jest: "npm:29.4.9"
typescript: "npm:5.9.3"
Expand Down
Loading