fix(tl): deprecate date parsing
This commit is contained in:
+19
-1
@@ -103,7 +103,7 @@ async function buildLiveTierlistConfig(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function shouldSnapshot(config: TierlistResolvedConfig) {
|
function shouldSnapshot(config: TierlistResolvedConfig) {
|
||||||
const deprecatedAt = Date.parse(config.version.deprecates);
|
const deprecatedAt = parseDate(config.version.deprecates);
|
||||||
const olderThanMonth =
|
const olderThanMonth =
|
||||||
Number.isFinite(deprecatedAt) &&
|
Number.isFinite(deprecatedAt) &&
|
||||||
deprecatedAt <= Date.now() - 30 * 24 * 60 * 60 * 1000;
|
deprecatedAt <= Date.now() - 30 * 24 * 60 * 60 * 1000;
|
||||||
@@ -120,6 +120,24 @@ function shouldSnapshot(config: TierlistResolvedConfig) {
|
|||||||
return olderThanMonth || allTiered;
|
return olderThanMonth || allTiered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseDate(value: string) {
|
||||||
|
const match = value.match(/^(\d{2})\/(\d{2})\/(\d{4})$/);
|
||||||
|
if (!match) return Number.NaN;
|
||||||
|
|
||||||
|
const [, day, month, year] = match;
|
||||||
|
const date = new Date(Number(year), Number(month) - 1, Number(day));
|
||||||
|
|
||||||
|
if (
|
||||||
|
date.getFullYear() !== Number(year) ||
|
||||||
|
date.getMonth() !== Number(month) - 1 ||
|
||||||
|
date.getDate() !== Number(day)
|
||||||
|
) {
|
||||||
|
return Number.NaN;
|
||||||
|
}
|
||||||
|
|
||||||
|
return date.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
async function maybeSnapshotVersion(
|
async function maybeSnapshotVersion(
|
||||||
tx: DbLike,
|
tx: DbLike,
|
||||||
version: typeof tierlistVersions.$inferSelect,
|
version: typeof tierlistVersions.$inferSelect,
|
||||||
|
|||||||
Reference in New Issue
Block a user