Skip to content

Commit

Permalink
Log error if date is unparseable
Browse files Browse the repository at this point in the history
  • Loading branch information
candela97 committed Apr 23, 2024
1 parent fb49952 commit 8491318
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/js/Content/Features/Community/ProfileStats/FAchievementSort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,18 @@ export default class FAchievementSort extends Feature<CProfileStats> {
}

const {format, formatNoYear, options} = dateSetup;
const fmt = /\d{4}/.test(dateString) ? format : formatNoYear;
const unlockedTime = DateTime.fromFormat(dateString, fmt, options).toUnixInteger();

if (Number.isNaN(unlockedTime)) {
this.logError(
new Error("Invalid unlocked time"),
`Failed to parse "${dateString}" with format "${fmt}"`
);
return;
}

const unlockedTime = DateTime.fromFormat(
dateString,
/\d{4}/.test(dateString) ? format : formatNoYear,
options
);

this.unlockedMap.set(achieveRow, unlockedTime.toUnixInteger());
this.unlockedMap.set(achieveRow, unlockedTime);
}
}

Expand Down Expand Up @@ -144,13 +148,18 @@ export default class FAchievementSort extends Feature<CProfileStats> {
}

const {format, formatNoYear} = dateSetup;
const fmt = /\d{4}/.test(dateString) ? format : formatNoYear;
const unlockedTime = DateTime.fromFormat(dateString, fmt).toUnixInteger();

if (Number.isNaN(unlockedTime)) {
this.logError(
new Error("Invalid unlocked time"),
`Failed to parse "${dateString}" with format "${fmt}"`
);
return;
}

const unlockedTime = DateTime.fromFormat(
dateString,
/\d{4}/.test(dateString) ? format : formatNoYear
);

this.unlockedMap.set(this.defaultSort[i], unlockedTime.toUnixInteger());
this.unlockedMap.set(this.defaultSort[i], unlockedTime);
}
}
}
Expand Down

0 comments on commit 8491318

Please sign in to comment.