🐛 修复日期判断错误

This commit is contained in:
目棃
2024-02-23 20:59:10 +08:00
parent a73b49a2c6
commit bf66b4eee0

View File

@@ -104,13 +104,12 @@ async function confirmCUD(): Promise<void> {
}, 4000); }, 4000);
} }
// 获取当天日期数字,如 20240204 // 判断是否超过一周
function getNowDate(): number { function isOverWeek(date: string): boolean {
const now = new Date(); const nowTs = Date.now();
const year = now.getFullYear().toString(); // 4位年份 const checkTs = new Date(date).getTime();
const month = (now.getMonth() + 1).toString().padStart(2, "0"); // 月份 const weekTs = 7 * 24 * 60 * 60 * 1000;
const day = now.getDate().toString().padStart(2, "0"); // 日期 return nowTs - checkTs >= weekTs;
return parseInt(year + month + day);
} }
async function confirmCLD(): Promise<void> { async function confirmCLD(): Promise<void> {
@@ -131,11 +130,9 @@ async function confirmCLD(): Promise<void> {
// yyyy-mm-dd.log // yyyy-mm-dd.log
const reg = /(\d{4}-\d{2}-\d{2}\.log)/; const reg = /(\d{4}-\d{2}-\d{2}\.log)/;
const match = file.path.match(reg); const match = file.path.match(reg);
if (match === null) { if (!Array.isArray(match) || match.length < 1) return false;
return false;
}
const date = match[1].replace(".log", ""); const date = match[1].replace(".log", "");
return getNowDate() - parseInt(date.replace(/-/g, "")) > 7; return isOverWeek(date);
}); });
if (delFiles.length < 1) { if (delFiles.length < 1) {
showSnackbar({ showSnackbar({