From 54200c8254000b1296962af0aeb32d8c0e730502 Mon Sep 17 00:00:00 2001 From: liufei Date: Sun, 9 Jan 2022 16:17:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dcron=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E6=89=A7=E8=A1=8Cbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Control/Other/BacklogNotificatin.xaml | 2 +- Control/Other/BacklogNotificatin.xaml.cs | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Control/Other/BacklogNotificatin.xaml b/Control/Other/BacklogNotificatin.xaml index e672b09..5b63d8d 100644 --- a/Control/Other/BacklogNotificatin.xaml +++ b/Control/Other/BacklogNotificatin.xaml @@ -15,7 +15,7 @@ - + diff --git a/Control/Other/BacklogNotificatin.xaml.cs b/Control/Other/BacklogNotificatin.xaml.cs index b00460d..be06ef4 100644 --- a/Control/Other/BacklogNotificatin.xaml.cs +++ b/Control/Other/BacklogNotificatin.xaml.cs @@ -40,13 +40,15 @@ namespace GeekDesk.Control.Other if (info.ExecType == TodoTaskExecType.CRON) { CronExpression exp = new CronExpression(info.Cron); - DateTime dtNow = DateTime.Now; - DateTimeOffset ddo = DateTime.SpecifyKind(dtNow, DateTimeKind.Local); - string nextExecTime = ddo.LocalDateTime.ToString("yyyy-MM-dd HH:mm:ss"); - info.ExeTime = nextExecTime; + DateTime nowTime = DateTime.Now; - DateTime nextTime = ddo.LocalDateTime; - TimeSpan ts = nextTime.Subtract(dtNow); + //计算下次执行时间 + DateTime nextTime = DateTime.SpecifyKind(exp.GetNextValidTimeAfter(nowTime).Value.LocalDateTime, DateTimeKind.Local); + + string nextTimeStr = nextTime.ToString("yyyy-MM-dd HH:mm:ss"); + info.ExeTime = nextTimeStr; + + TimeSpan ts = nextTime.Subtract(nowTime); int minutes = (int)Math.Ceiling(ts.TotalMinutes); if (minutes < 0) { @@ -62,7 +64,8 @@ namespace GeekDesk.Control.Other { Growl.SuccessGlobal("下次任务将在 " + minutes + " 分钟后提醒您!"); } - } else + } + else { appData.ToDoList.Remove(info); //执行任务删除 appData.HiToDoList.Add(info); //添加历史任务 @@ -120,7 +123,7 @@ namespace GeekDesk.Control.Other ToDoInfo info = this.DataContext as ToDoInfo; int time = int.Parse(DelayTime.Text); string type = DelayType.Text; - switch(type) + switch (type) { case "分": info.ExeTime = DateTime.Now.AddMinutes(time).ToString("yyyy-MM-dd HH:mm:ss");