评估复杂的时间模式 [英] Evaluate complex time patterns

查看:102
本文介绍了评估复杂的时间模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想定义和评估某些非常复杂的时间模式的发生,而这些时间模式无法轻易地由CRON表达式处理.有没有可以帮助我做到这一点的图书馆?

I would like to define and evaluate ocurrences of some very complex time patterns that cannot be handled by CRON expressions easily. Is there any library that help me to do that?

例如:

  1. 我希望每25秒发生一次.
  2. 我只希望在一个月的第一天和最后一天出现.但是每月的第一天应该让我在9:00 AM和11:00 AM之间有5分钟的分辨率.该月的最后一天应评估为上午5:00.
  3. 我想创建一个非常复杂的时间模式,执行以下操作:

  1. I would like it to occur every 25 seconds.
  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. The last day of month should evaluate to 5:00AM.
  3. I would like to create very complex time pattern that do something like this:

每月第一周和第三周的星期一在8:30 AM和11:30 AM之间有时间 第二周和第四周的周二和周日下午12:00

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

是否可以用某种表达形式表达此类要求并评估其适合的日期?我应该使用什么,在哪里找到它?

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?

推荐答案

我是评估此类表达式的库的作者.它是特定于域的语言,看起来有点像SQL,因此许多用户应该熟悉它的语法.对于询问的表达式:

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. For the asked expressions:

我希望每25秒发生一次.

I would like it to occur every 25 seconds.

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

我只希望在一个月的第一天和最后一天出现.但是每月的第一天应该让我在9:00 AM和11:00 AM之间有5分钟的分辨率.一个月的最后一天应评估为上午5: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. The last day of month should evaluate to 5:00AM.

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 AM到11:30 AM之间的时间在第二周和第四周的星期二和星期日的中午12:00 PM

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

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)具有用于更改策略的可选类型参数.

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.

可以注意到,包含where部分的查询允许在当前时间轴上应用复杂的过滤器.您只需像在SQL中一样编写过滤器,但是将过滤时间轴,而不是数据.

As it can be noted, queries that contains where part allows to apply sophisticated filters on current timeline. You simply write your filters like you would do in SQL but you will filter timeline, not datas.

几乎没有内置函数可以帮助更快地设计新查询.还可以开发其他过滤器功能.请参见 wiki 中的默认内容.所有这些函数都是用纯C#编写的,添加自定义函数应该很容易.在 nuget 上可用.我希望这个库对社区有用.

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. All those functions were written in pure C# and it should be easy to add custom functions. It's available on nuget. I would like this library to be usefull for community.

我还制作了cron评估程序,该评估程序共享抽象,因此可以互换使用,因为有时最好使用cron代替.

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.

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

这篇关于评估复杂的时间模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆