20260719215738
This commit is contained in:
1 parent
35aa108a34
commit
cda7f16d3a
116 files changed
+11826
-3669
No files matched your search
@@ -15,7 +15,11 @@ function cleanRepeatDate(repeatDate: string): string {
|
||||
* 粗粒度判断:从上次执行至今,是否"可能"有遗漏的触发日期
|
||||
* 只做时间周期级别的判断,不做具体日期匹配(日期匹配交给 shouldRunOnDate / getMissedDates)
|
||||
*/
|
||||
export function shouldRun(repeatType: number, repeatDate: string, lastRun: string | null | undefined): boolean {
|
||||
export function shouldRun(
|
||||
repeatType: number,
|
||||
repeatDate: string,
|
||||
lastRun: string | null | undefined,
|
||||
): boolean {
|
||||
const today = dayjs();
|
||||
if (!lastRun) return true; // 从未执行过,需要尝试
|
||||
|
||||
@@ -31,7 +35,10 @@ export function shouldRun(repeatType: number, repeatDate: string, lastRun: strin
|
||||
return !last.isSame(today, "day");
|
||||
|
||||
case FinanceAutoRepeatType.Weekly: {
|
||||
const days = (repeatDate || "").split(",").map(Number).filter((d) => !isNaN(d));
|
||||
const days = (repeatDate || "")
|
||||
.split(",")
|
||||
.map(Number)
|
||||
.filter((d) => !isNaN(d));
|
||||
if (days.length === 0) return false;
|
||||
let check = today;
|
||||
for (let i = 0; i < 7; i++) {
|
||||
@@ -100,12 +107,18 @@ function shouldRunOnDate(repeatType: number, repeatDate: string, date: dayjs.Day
|
||||
case FinanceAutoRepeatType.Daily: {
|
||||
if (!exclude || !raw) return true;
|
||||
// 每天 排除星期几(如 "!0" → 排除周日)
|
||||
const excludedDays = raw.split(",").map(Number).filter((d) => !isNaN(d));
|
||||
const excludedDays = raw
|
||||
.split(",")
|
||||
.map(Number)
|
||||
.filter((d) => !isNaN(d));
|
||||
return !excludedDays.includes(date.day());
|
||||
}
|
||||
|
||||
case FinanceAutoRepeatType.Weekly: {
|
||||
const days = raw.split(",").map(Number).filter((d) => !isNaN(d));
|
||||
const days = raw
|
||||
.split(",")
|
||||
.map(Number)
|
||||
.filter((d) => !isNaN(d));
|
||||
if (days.length === 0) return false;
|
||||
const match = days.includes(date.day());
|
||||
return exclude ? !match : match;
|
||||
@@ -113,7 +126,10 @@ function shouldRunOnDate(repeatType: number, repeatDate: string, date: dayjs.Day
|
||||
|
||||
case FinanceAutoRepeatType.Monthly:
|
||||
case FinanceAutoRepeatType.Quarterly: {
|
||||
const dates = raw.split(",").map(Number).filter((d) => !isNaN(d));
|
||||
const dates = raw
|
||||
.split(",")
|
||||
.map(Number)
|
||||
.filter((d) => !isNaN(d));
|
||||
if (dates.length === 0) return false;
|
||||
const match = dates.includes(date.date());
|
||||
return exclude ? !match : match;
|
||||
@@ -121,7 +137,10 @@ function shouldRunOnDate(repeatType: number, repeatDate: string, date: dayjs.Day
|
||||
|
||||
case FinanceAutoRepeatType.Yearly: {
|
||||
// 月,日 成对存储,如 "3,15,6,1" → 3月15日 + 6月1日
|
||||
const parts = raw.split(",").map(Number).filter((n) => !isNaN(n));
|
||||
const parts = raw
|
||||
.split(",")
|
||||
.map(Number)
|
||||
.filter((n) => !isNaN(n));
|
||||
for (let i = 0; i < parts.length - 1; i += 2) {
|
||||
if (parts[i] === date.month() + 1 && parts[i + 1] === date.date()) {
|
||||
return exclude ? false : true;
|
||||
|
||||
@@ -16,11 +16,7 @@ export async function requestNotificationPermission(): Promise<boolean> {
|
||||
}
|
||||
|
||||
// -- 预定提醒通知 --
|
||||
export async function scheduleTodoReminder(
|
||||
todoId: number,
|
||||
todoName: string,
|
||||
remindAt: string,
|
||||
) {
|
||||
export async function scheduleTodoReminder(todoId: number, todoName: string, remindAt: string) {
|
||||
if (!remindAt) return null;
|
||||
|
||||
const triggerDate = new Date(remindAt);
|
||||
|
||||
Reference in new issue
Block a user