feat: last checked and next refresh
This commit is contained in:
+14
-10
@@ -1,5 +1,5 @@
|
||||
import type { RawTask, Task } from "@/types";
|
||||
import CronExpressionParser from "cron-parser";
|
||||
import {CronExpressionParser} from "cron-parser";
|
||||
|
||||
export function parseTask(task: RawTask): Task {
|
||||
return {
|
||||
@@ -13,18 +13,22 @@ export function parseTask(task: RawTask): Task {
|
||||
};
|
||||
}
|
||||
|
||||
export function taskCompleted(task: Task): boolean {
|
||||
if (task.check_date === null) {
|
||||
return false;
|
||||
}
|
||||
if (task.reset_cron === null) {
|
||||
return true;
|
||||
export function taskNextReset(task: Task): Date | null {
|
||||
if (task.check_date === null || task.reset_cron === null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
const interval = CronExpressionParser.parse(task.reset_cron, {currentDate: task.check_date});
|
||||
const nextDate = interval.next();
|
||||
return nextDate.getTime() > (new Date()).getTime();
|
||||
return interval.next().toDate();
|
||||
} catch {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function taskCompleted(task: Task): boolean {
|
||||
const nextReset = taskNextReset(task);
|
||||
if (nextReset === null) {
|
||||
return task.check_date !== null;
|
||||
}
|
||||
return nextReset.getTime() > (new Date()).getTime();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user