Skip to content

Commit 6d709fe

Browse files
committed
Refactor date parsing in usage-report.service.ts
1 parent 9739a7d commit 6d709fe

File tree

1 file changed

+1
-13
lines changed

1 file changed

+1
-13
lines changed

src/app/usage-report.service.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,14 @@ const readGithubUsageReport = async (data: string, cb?: (usageReport: UsageRepor
1616

1717
const lines = data.split('\n');
1818
total = lines.length;
19-
const first = lines[1].split(',')[0];
20-
const dateDelim = first.includes('-') ? '-' : first.includes('/') ? '/' : null;
21-
if (dateDelim == null) throw new Error('Invalid date delimiter');
2219
for (const line of lines) {
2320
if (index == 0) {
2421
index++;
2522
continue;
2623
}
2724
const csv = line.split(',');
28-
let month, day, year;
29-
if (dateDelim === '/') {
30-
[month, day, year] = csv[0].split('/').map(Number);
31-
year = 2000 + year;
32-
} else if (dateDelim === '-') {
33-
[year, month, day] = csv[0].split('-').map(Number);
34-
}
35-
if (!year || !month || !day) throw new Error('Invalid date');
36-
const date = new Date(year, month - 1, day);
3725
const data: UsageReportLine = {
38-
date,
26+
date: new Date(Date.parse(csv[0])),
3927
product: csv[1],
4028
sku: csv[2],
4129
quantity: Number(csv[3]),

0 commit comments

Comments
 (0)