Skip to content

Commit 96cef5a

Browse files
committed
Fixed cross months event dates
1 parent e10b856 commit 96cef5a

File tree

4 files changed

+48
-39
lines changed

4 files changed

+48
-39
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ node_modules
22
dist
33
junk * log.env
44

5-
src/index.ts
5+
src/index.ts
6+
commit.bat

__tests__/__snapshots__/race-results.test.ts.snap

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,139 +4,139 @@ exports[`get race results 1`] = `
44
[
55
{
66
"car": "Ferrari",
7-
"date": 2000-03-11T23:00:00.000Z,
7+
"date": 2000-03-12T08:00:00.000Z,
88
"grandPrix": "Australia",
99
"laps": 58,
1010
"time": "1:34:01.987",
11-
"winner": "Michael Schumacher",
11+
"winner": "Michael Schumacher",
1212
},
1313
{
1414
"car": "Ferrari",
15-
"date": 2000-03-25T23:00:00.000Z,
15+
"date": 2000-03-26T08:00:00.000Z,
1616
"grandPrix": "Brazil",
1717
"laps": 71,
1818
"time": "1:31:35.271",
19-
"winner": "Michael Schumacher",
19+
"winner": "Michael Schumacher",
2020
},
2121
{
2222
"car": "Ferrari",
23-
"date": 2000-04-08T22:00:00.000Z,
23+
"date": 2000-04-09T07:00:00.000Z,
2424
"grandPrix": "San Marino",
2525
"laps": 62,
2626
"time": "1:31:39.776",
27-
"winner": "Michael Schumacher",
27+
"winner": "Michael Schumacher",
2828
},
2929
{
3030
"car": "McLaren Mercedes",
31-
"date": 2000-04-22T22:00:00.000Z,
31+
"date": 2000-04-23T07:00:00.000Z,
3232
"grandPrix": "Great Britain",
3333
"laps": 60,
3434
"time": "1:28:50.108",
35-
"winner": "David Coulthard",
35+
"winner": "David Coulthard",
3636
},
3737
{
3838
"car": "McLaren Mercedes",
39-
"date": 2000-05-06T22:00:00.000Z,
39+
"date": 2000-05-07T07:00:00.000Z,
4040
"grandPrix": "Spain",
4141
"laps": 65,
4242
"time": "1:33:55.390",
43-
"winner": "Mika Hakkinen",
43+
"winner": "Mika Hakkinen",
4444
},
4545
{
4646
"car": "Ferrari",
47-
"date": 2000-05-20T22:00:00.000Z,
47+
"date": 2000-05-21T07:00:00.000Z,
4848
"grandPrix": "Europe",
4949
"laps": 67,
5050
"time": "1:42:00.307",
51-
"winner": "Michael Schumacher",
51+
"winner": "Michael Schumacher",
5252
},
5353
{
5454
"car": "McLaren Mercedes",
55-
"date": 2000-06-03T22:00:00.000Z,
55+
"date": 2000-06-04T07:00:00.000Z,
5656
"grandPrix": "Monaco",
5757
"laps": 78,
5858
"time": "1:49:28.213",
59-
"winner": "David Coulthard",
59+
"winner": "David Coulthard",
6060
},
6161
{
6262
"car": "Ferrari",
63-
"date": 2000-06-17T22:00:00.000Z,
63+
"date": 2000-06-18T07:00:00.000Z,
6464
"grandPrix": "Canada",
6565
"laps": 69,
6666
"time": "1:41:12.313",
67-
"winner": "Michael Schumacher",
67+
"winner": "Michael Schumacher",
6868
},
6969
{
7070
"car": "McLaren Mercedes",
71-
"date": 2000-07-01T22:00:00.000Z,
71+
"date": 2000-07-02T07:00:00.000Z,
7272
"grandPrix": "France",
7373
"laps": 72,
7474
"time": "1:38:05.538",
75-
"winner": "David Coulthard",
75+
"winner": "David Coulthard",
7676
},
7777
{
7878
"car": "McLaren Mercedes",
79-
"date": 2000-07-15T22:00:00.000Z,
79+
"date": 2000-07-16T07:00:00.000Z,
8080
"grandPrix": "Austria",
8181
"laps": 71,
8282
"time": "1:28:15.818",
83-
"winner": "Mika Hakkinen",
83+
"winner": "Mika Hakkinen",
8484
},
8585
{
8686
"car": "Ferrari",
87-
"date": 2000-07-29T22:00:00.000Z,
87+
"date": 2000-07-30T07:00:00.000Z,
8888
"grandPrix": "Germany",
8989
"laps": 45,
9090
"time": "1:25:34.418",
91-
"winner": "Rubens Barrichello",
91+
"winner": "Rubens Barrichello",
9292
},
9393
{
9494
"car": "McLaren Mercedes",
95-
"date": 2000-08-12T22:00:00.000Z,
95+
"date": 2000-08-13T07:00:00.000Z,
9696
"grandPrix": "Hungary",
9797
"laps": 77,
9898
"time": "1:45:33.869",
99-
"winner": "Mika Hakkinen",
99+
"winner": "Mika Hakkinen",
100100
},
101101
{
102102
"car": "McLaren Mercedes",
103-
"date": 2000-08-26T22:00:00.000Z,
103+
"date": 2000-08-27T07:00:00.000Z,
104104
"grandPrix": "Belgium",
105105
"laps": 44,
106106
"time": "1:28:14.494",
107-
"winner": "Mika Hakkinen",
107+
"winner": "Mika Hakkinen",
108108
},
109109
{
110110
"car": "Ferrari",
111-
"date": 2000-09-09T22:00:00.000Z,
111+
"date": 2000-09-10T07:00:00.000Z,
112112
"grandPrix": "Italy",
113113
"laps": 53,
114114
"time": "1:27:31.638",
115-
"winner": "Michael Schumacher",
115+
"winner": "Michael Schumacher",
116116
},
117117
{
118118
"car": "Ferrari",
119-
"date": 2000-09-23T22:00:00.000Z,
119+
"date": 2000-09-24T07:00:00.000Z,
120120
"grandPrix": "United States",
121121
"laps": 73,
122122
"time": "1:36:30.883",
123-
"winner": "Michael Schumacher",
123+
"winner": "Michael Schumacher",
124124
},
125125
{
126126
"car": "Ferrari",
127-
"date": 2000-10-07T22:00:00.000Z,
127+
"date": 2000-10-08T07:00:00.000Z,
128128
"grandPrix": "Japan",
129129
"laps": 53,
130130
"time": "1:29:53.435",
131-
"winner": "Michael Schumacher",
131+
"winner": "Michael Schumacher",
132132
},
133133
{
134134
"car": "Ferrari",
135-
"date": 2000-10-21T22:00:00.000Z,
135+
"date": 2000-10-22T07:00:00.000Z,
136136
"grandPrix": "Malaysia",
137137
"laps": 56,
138138
"time": "1:35:54.235",
139-
"winner": "Michael Schumacher",
139+
"winner": "Michael Schumacher",
140140
},
141141
]
142-
`;
142+
`;

__tests__/__snapshots__/race-schedule.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ exports[`get race schedule 1`] = `
5757
"round": "ROUND 8",
5858
},
5959
{
60-
"date": "30May-01Jun",
60+
"date": "30-01May-Jun",
6161
"eventTitle": "FORMULA 1 ARAMCO GRAN PREMIO DE ESPAÑA 2025",
6262
"raceCountry": "Spain",
6363
"round": "ROUND 9",
@@ -153,4 +153,4 @@ exports[`get race schedule 1`] = `
153153
"round": "ROUND 24",
154154
},
155155
]
156-
`;
156+
`;

src/scraper/race-schedule.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,18 @@ export const getRaceSchedule = async (year: number = new Date().getFullYear()):
4242
//Semantics differ for the next race
4343
if (raceCountry === "") raceCountry = $(this).find("div:nth-child(1) > div:nth-child(2) > span:nth-child(2) > p:nth-child(2)").text().trim();
4444

45+
date = date.replaceAll(" ", "");
46+
47+
//Cross-month
48+
if (date.length > 8) {
49+
const dateParts: string[] = [date.slice(0, 2), date.slice(2, 5), date.slice(6, 8), date.slice(8, 13)];
50+
date = `${dateParts[0]}-${dateParts[2]}${dateParts[1]}-${dateParts[3]}`;
51+
}
52+
4553
if (round !== undefined && raceCountry !== undefined && eventTitle !== undefined) {
4654
const singleSchedule = {
4755
round,
48-
date: date.replaceAll(" ", ""),
56+
date,
4957
raceCountry,
5058
eventTitle,
5159
};

0 commit comments

Comments
 (0)