Skip to content

Commit

Permalink
Fix date parsing issue in chart-line-usage-daily.component.ts and usa…
Browse files Browse the repository at this point in the history
…ge-report.service.ts
  • Loading branch information
austenstone committed Feb 6, 2024
1 parent 4ccd8ef commit 993a1b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,18 @@ export class ChartLineUsageDailyComponent implements OnChanges {
if (!series.data[timeKey]) series.data[timeKey] = [];
if (timeKey === 'total') {
const last = series.data[timeKey][series.data[timeKey].length - 1];
series.data[timeKey].push([new Date(line.date).getTime(), (last[1] + line.value)]);
series.data[timeKey].push([line.date.getTime(), (last[1] + line.value)]);
} else if (this.timeType.startsWith('rolling')) {
series.data[timeKey].push([new Date(line.date).getTime(), line.value]);
series.data[timeKey].push([line.date.getTime(), line.value]);
} else {
series.data[timeKey].push([new Date(line.date).getTime(), line.value]);
series.data[timeKey].push([line.date.getTime(), line.value]);
}
series.total += line.value;
} else {
acc.push({
name,
data: {
[timeKey]: [[new Date(line.date).getTime(), line.value]]
[timeKey]: [[line.date.getTime(), line.value]]
},
total: line.value
});
Expand Down
11 changes: 10 additions & 1 deletion src/app/usage-report.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@ 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(',');
const [year, month, day] = csv[0].split(/-|\//).map(Number);
let month, day, year;
if (dateDelim === '/') {
[month, day, year] = csv[0].split('/').map(Number);
} 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,
Expand Down

0 comments on commit 993a1b5

Please sign in to comment.