我是评估此类表达式的库的作者。它是一种特定于领域的语言,看起来有点像 SQL,所以很多用户应该熟悉它的语法。对于被问到的表达方式:
我希望它每 25 秒发生一次。
repeat every 25 seconds start at '29.10.2017 01:55:00'
我只想在每月的第一天和最后一天发生。但是一个月的第一天应该让我在上午 9:00 和上午 11:00 之间获得 5 分钟的分辨率。一个月的最后一天应计算为凌晨 5:00。
repeat every minutes where 1 =
(case
when GetDay() = 1 and GetHour() between 9 and 11
then GetMinute() % 5 = 0
when IsLastDayOfMonth()
then GetHour() = 5 and GetMinute() = 0 and GetSecond() = 0
else 0
esac) start at '01.01.2017'
每月第一周和第三周的星期一上午 8:30 至上午 11:30 时间为第二周和第四周的星期二和星期日下午 12:00
repeat every minutes where 1 =
(case
when GetWeekOfMonth() in (1,3) and GetDayOfWeek() = monday
then GetTime() between Time(8, 30, 0) and Time(11, 30, 0)
when GetWeekOfMonth() in (2,4) and GetDayOfWeek() in (tuesday, sunday)
then GetTime() = Time(12, 0, 0)
else 0
esac) start at '01.04.2017'
这里值得指出的是,通常可以以不同的方式计算月份的周数,没有标准的方法来执行此操作,因此结果可能会因选择的策略而异。 GetWeekOfMonth(string type) 具有改变策略的可选类型参数。
可以注意到,包含where 部分的查询允许在当前时间线上应用复杂的过滤器。您只需像在 SQL 中那样编写过滤器,但您将过滤时间线,而不是数据。
很少有内置函数可以帮助更快地设计新查询。也可以开发其他过滤器功能。请参阅wiki 中的默认设置。所有这些函数都是用纯 C# 编写的,并且应该很容易添加自定义函数。它在 nuget 上可用。我希望这个库对社区有用。
我还制作了共享抽象的 cron 评估器,因此可以互换使用它,因为有时使用 cron 会更好。
https://github.com/Puchaczov/TQL.RDL