Skip to content

Commit 740b8ef

Browse files
Football Data Pages - Use ISO string instead of dates (#13547)
* update fixture
1 parent dd52492 commit 740b8ef

File tree

4 files changed

+34
-22
lines changed

4 files changed

+34
-22
lines changed

dotcom-rendering/fixtures/manual/footballData.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const regions: Regions = [
2121

2222
export const initialDays: FootballMatches = [
2323
{
24-
date: new Date('2022-01-01T00:00:00Z'),
24+
dateISOString: new Date('2022-01-01T00:00:00Z').toISOString(),
2525
competitions: [
2626
{
2727
id: '635',
@@ -31,7 +31,9 @@ export const initialDays: FootballMatches = [
3131
matches: [
3232
{
3333
kind: 'Live',
34-
dateTime: new Date('2022-01-01T11:11:00Z'),
34+
dateTimeISOString: new Date(
35+
'2022-01-01T11:11:00Z',
36+
).toISOString(),
3537
paId: '4482093',
3638
homeTeam: {
3739
name: 'Torino',
@@ -45,7 +47,9 @@ export const initialDays: FootballMatches = [
4547
},
4648
{
4749
kind: 'Fixture',
48-
dateTime: new Date('2022-01-01T19:45:00Z'),
50+
dateTimeISOString: new Date(
51+
'2022-01-01T19:45:00Z',
52+
).toISOString(),
4953
paId: '4482890',
5054
homeTeam: 'Auxerre',
5155
awayTeam: 'St Etienne',
@@ -60,7 +64,9 @@ export const initialDays: FootballMatches = [
6064
matches: [
6165
{
6266
kind: 'Result',
63-
dateTime: new Date('2022-01-01T20:00:00Z'),
67+
dateTimeISOString: new Date(
68+
'2022-01-01T20:00:00Z',
69+
).toISOString(),
6470
paId: '4482835',
6571
homeTeam: {
6672
name: 'Las Palmas',
@@ -82,7 +88,9 @@ export const initialDays: FootballMatches = [
8288
matches: [
8389
{
8490
kind: 'Result',
85-
dateTime: new Date('2022-01-01T20:00:00Z'),
91+
dateTimeISOString: new Date(
92+
'2022-01-01T20:00:00Z',
93+
).toISOString(),
8694
paId: '4482836',
8795
homeTeam: {
8896
name: 'Brighton & Hove Albion Women',
@@ -103,7 +111,7 @@ export const initialDays: FootballMatches = [
103111

104112
export const moreDays: FootballMatches = [
105113
{
106-
date: new Date('2022-01-05T00:00:00Z'),
114+
dateISOString: new Date('2022-01-05T00:00:00Z').toISOString(),
107115
competitions: [
108116
{
109117
id: '635',
@@ -113,7 +121,9 @@ export const moreDays: FootballMatches = [
113121
matches: [
114122
{
115123
kind: 'Fixture',
116-
dateTime: new Date('2022-01-05T19:45:00Z'),
124+
dateTimeISOString: new Date(
125+
'2022-01-05T19:45:00Z',
126+
).toISOString(),
117127
paId: '4482890',
118128
homeTeam: 'Juventus',
119129
awayTeam: 'Roma',

dotcom-rendering/src/components/FootballMatchList.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ const MatchStatus = ({
153153
return (
154154
<time
155155
css={matchStatusStyles}
156-
dateTime={match.dateTime.toISOString()}
156+
dateTime={match.dateTimeISOString}
157157
>
158-
{timeFormatter.format(match.dateTime)}
158+
{timeFormatter.format(new Date(match.dateTimeISOString))}
159159
</time>
160160
);
161161
}
@@ -194,7 +194,7 @@ const MatchWrapper = ({
194194
now: Date;
195195
children: ReactNode;
196196
}) => {
197-
if (shouldRenderMatchLink(match.dateTime, now)) {
197+
if (shouldRenderMatchLink(new Date(match.dateTimeISOString), now)) {
198198
return (
199199
<li css={matchListItemStyles}>
200200
<a
@@ -388,9 +388,11 @@ export const FootballMatchList = ({
388388
}
389389
}
390390
`}
391-
key={day.date.toISOString()}
391+
key={day.dateISOString}
392392
>
393-
<Day>{dateFormatter.format(day.date)}</Day>
393+
<Day>
394+
{dateFormatter.format(new Date(day.dateISOString))}
395+
</Day>
394396
{day.competitions.map((competition) => (
395397
<Fragment key={competition.id}>
396398
<CompetitionName>

dotcom-rendering/src/footballMatches.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('footballMatches', () => {
3636
expect(result.length).toBe(1);
3737

3838
const day = result[0];
39-
expect(day?.date.toISOString()).toBe('2025-03-03T00:00:00.000Z');
39+
expect(day?.dateISOString).toBe('2025-03-03T00:00:00.000Z');
4040
expect(day?.competitions.length).toBe(3);
4141

4242
const competition = day?.competitions[0];

dotcom-rendering/src/footballMatches.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type TeamScore = {
2121

2222
type MatchData = {
2323
paId: string;
24-
dateTime: Date;
24+
dateTimeISOString: string;
2525
};
2626

2727
export type MatchResult = MatchData & {
@@ -57,7 +57,7 @@ type Competition = {
5757
};
5858

5959
type FootballDay = {
60-
date: Date;
60+
dateISOString: string;
6161
competitions: Competition[];
6262
};
6363

@@ -162,14 +162,14 @@ const listParse =
162162
return f(input, []);
163163
};
164164

165-
const parseDate = (a: string): Result<string, Date> => {
165+
const parseDate = (a: string): Result<string, string> => {
166166
const d = new Date(a);
167167

168168
if (d.toString() === 'Invalid Date') {
169169
return error(`${String(a)} isn't a valid Date`);
170170
}
171171

172-
return ok(d);
172+
return ok(d.toISOString());
173173
};
174174

175175
const parseScore = (
@@ -188,7 +188,7 @@ const parseScore = (
188188
return ok(team.score);
189189
};
190190

191-
const parseMatchDate = (date: string): Result<string, Date> => {
191+
const parseMatchDate = (date: string): Result<string, string> => {
192192
// Frontend appends a timezone in square brackets
193193
const isoDate = date.split('[')[0];
194194

@@ -224,7 +224,7 @@ const parseFixture = (
224224
kind: 'Fixture',
225225
homeTeam: cleanTeamName(feFixture.homeTeam.name),
226226
awayTeam: cleanTeamName(feFixture.awayTeam.name),
227-
dateTime: date.value,
227+
dateTimeISOString: date.value,
228228
paId: feFixture.id,
229229
});
230230
};
@@ -267,7 +267,7 @@ export const parseMatchResult = (
267267
name: cleanTeamName(feResult.awayTeam.name),
268268
score: awayScore.value,
269269
},
270-
dateTime: date.value,
270+
dateTimeISOString: date.value,
271271
paId: feResult.id,
272272
comment: feResult.comments,
273273
});
@@ -311,7 +311,7 @@ const parseLiveMatch = (
311311
name: cleanTeamName(feMatchDay.awayTeam.name),
312312
score: awayScore.value,
313313
},
314-
dateTime: date.value,
314+
dateTimeISOString: date.value,
315315
paId: feMatchDay.id,
316316
comment: feMatchDay.comments,
317317
status: feMatchDay.matchStatus,
@@ -393,7 +393,7 @@ const parseFootballDay = (
393393
}
394394

395395
return ok({
396-
date: date.value,
396+
dateISOString: date.value,
397397
competitions: competitions.value,
398398
});
399399
};

0 commit comments

Comments
 (0)