简体   繁体   English

评估复杂的时间模式

[英]Evaluate complex time patterns

I would like to define and evaluate ocurrences of some very complex time patterns that cannot be handled by CRON expressions easily. 我想定义和评估一些非常复杂的时间模式的发生,而这些时间模式无法通过CRON表达式轻松处理。 Is there any library that help me to do that? 有没有可以帮助我做到这一点的图书馆?

For example: 例如:

  1. I would like it to occur every 25 seconds. 我希望每25秒发生一次。
  2. I would like to occur only first and last day of month. 我只想在一个月的第一天和最后一天出现。 But first day of month should gets me resolution of 5 minutes betwen 9:00AM and 11:00AM. 但是每月的第一天应该让我在9:00 AM和11:00 AM之间有5分钟的分辨率。 The last day of month should evaluate to 5:00AM. 该月的最后一天应评估为5:00 AM。
  3. I would like to create very complex time pattern that do something like this: 我想创建一个非常复杂的时间模式,执行以下操作:

    On monday of first and third week of month gets time between 8:30AM and 11:30AM On tuesday and sunday of second and fourth week time at 12:00PM 每个月的第一周和第三周的星期一在8:30 AM和11:30 AM之间获得时间,第二周和第四周的星期二和星期天的12:00 PM

Is it possible to express such requirements in some form of expression and evaluate what dates it fits? 是否有可能以某种表达形式表达这种要求并评估其适合的日期? What should I use, where to find it? 我应该使用什么,在哪里找到它?

I am author of library that evaluates such expressions. 我是评估此类表达式的库的作者。 It's domain specific language that looks a bit like SQL so lots of user should be familiar with it's syntax. 它是特定于域的语言,看起来有点像SQL,因此许多用户应该熟悉它的语法。 For the asked expressions: 对于要求的表达式:

I would like it to occur every 25 seconds. 我希望每25秒发生一次。

repeat every 25 seconds start at '29.10.2017 01:55:00'

I would like to occur only first and last day of month. 我只想在一个月的第一天和最后一天出现。 But first day of month should gets me resolution of 5 minutes betwen 9:00AM and 11:00AM. 但是每月的第一天应该让我在9:00 AM和11:00 AM之间有5分钟的分辨率。 The last day of month should evaluate to 5:00AM. 该月的最后一天应评估为5:00 AM。

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'

On monday of first and third week of month gets time between 8:30AM and 11:30AM On tuesday and sunday of second and fourth week time at 12:00PM 每个月的第一周和第三周的星期一在8:30 AM和11:30 AM之间获得时间,第二周和第四周的星期二和星期天的12:00 PM

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'

As worth to point here is that generally week of months can be calucated differently, there is no standard way of doing this so results may varing dependly on what strategy was chosen. 值得指出的是,通常每个月的周数可以不同地计算,没有标准的方法可以执行,因此结果可能会因所选择的策略而异。 GetWeekOfMonth(string type) have optional type parameter that changes strategy. GetWeekOfMonth(string type)具有更改策略的可选type参数。

As it can be noted, queries that contains where part allows to apply sophisticated filters on current timeline. 正如可以注意到,包含查询where部分允许对当前时间轴应用复杂的过滤器。 You simply write your filters like you would do in SQL but you will filter timeline, not datas. 您只需像在SQL中一样编写过滤器,但是将过滤时间轴,而不是数据。

There are few build-in functions to help faster designing new queries. 很少有内置函数可以帮助更快地设计新查询。 It's also possible to develop other filter functions. 还可以开发其他过滤器功能。 See defaultly available in wiki . 请参阅Wiki中默认可用的内容。 All those functions were written in pure C# and it should be easy to add custom functions. 所有这些函数都是用纯C#编写的,添加自定义函数应该很容易。 It's available on nuget . nuget可用 I would like this library to be usefull for community. 我希望这个图书馆对社区有用。

I made also cron evaluator that share abstractions so it is possible to use it interchangeably becouse sometimes it's much better to use cron instead. 我还使cron评估程序共享了抽象,因此可以互换使用它,因为有时最好改用cron。

https://github.com/Puchaczov/TQL.RDL https://github.com/Puchaczov/TQL.RDL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM