Skip to content

Commit

Permalink
Refactor date parsing in usage-report.service.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
austenstone committed Feb 6, 2024
1 parent 9739a7d commit 6d709fe
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions src/app/usage-report.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,14 @@ const readGithubUsageReport = async (data: string, cb?: (usageReport: UsageRepor

const lines = data.split('\n');
total = lines.length;
const first = lines[1].split(',')[0];
const dateDelim = first.includes('-') ? '-' : first.includes('/') ? '/' : null;
if (dateDelim == null) throw new Error('Invalid date delimiter');
for (const line of lines) {
if (index == 0) {
index++;
continue;
}
const csv = line.split(',');
let month, day, year;
if (dateDelim === '/') {
[month, day, year] = csv[0].split('/').map(Number);
year = 2000 + year;
} else if (dateDelim === '-') {
[year, month, day] = csv[0].split('-').map(Number);
}
if (!year || !month || !day) throw new Error('Invalid date');
const date = new Date(year, month - 1, day);
const data: UsageReportLine = {
date,
date: new Date(Date.parse(csv[0])),
product: csv[1],
sku: csv[2],
quantity: Number(csv[3]),
Expand Down

0 comments on commit 6d709fe

Please sign in to comment.