Skip to content

Commit

Permalink
update useless code (#545)
Browse files Browse the repository at this point in the history
  • Loading branch information
l1tok authored Dec 4, 2022
1 parent aa936b6 commit e5e8df9
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions src/utils/data.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
export const generateDataByMonth = (originalData: any) => {
const objectData: any = {};
// format month string
Object.keys(originalData).forEach((key) => {
// following wrapper code is for adaption purpose, see issue #541
let date = key;
// handle old date format, e.g. 20204 -> 2020-04
if (!key.includes('-')) {
date = key.slice(0, 4) + '-' + key.slice(4).toString().padStart(2, '0');
}
objectData[date] = originalData[key];
});
// get the oldest month and the newest one
const orderedMonths = Object.keys(objectData).sort((a, b) => {
const orderedMonths = Object.keys(originalData).sort((a, b) => {
const dateA = new Date(a);
const dateB = new Date(b);
if (dateA < dateB) return -1;
Expand All @@ -27,10 +15,10 @@ export const generateDataByMonth = (originalData: any) => {
for (let i = start; i <= end; i.setMonth(i.getMonth() + 1)) {
const date =
i.getFullYear() + '-' + (i.getMonth() + 1).toString().padStart(2, '0');
if (!objectData.hasOwnProperty(date)) {
if (!originalData.hasOwnProperty(date)) {
arrayData.push([date, 0]);
} else {
arrayData.push([date, objectData[date]]);
arrayData.push([date, originalData[date]]);
}
}
return arrayData;
Expand Down

0 comments on commit e5e8df9

Please sign in to comment.