Quartz.NET - 使用/ cron的理解基于触发器和时区/夏令时(夏令时间) [英] Quartz.NET - Using/understanding cron based trigger and time zone/summertime (daylight saving time)

查看:612
本文介绍了Quartz.NET - 使用/ cron的理解基于触发器和时区/夏令时(夏令时间)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关为例缘故让使用下面的cron表达式:0 0 1 14 *结果
- >每月在14:00第一天火。

For sake of an example lets use the following cron expression: "0 0 14 1 * ?"
-> Fire on the 1st day of every month at 14:00 hours.

我用石英CronScheduleBuilder打造expession,但是这是不相关的。

I used the Quartz CronScheduleBuilder to build the expession, but this is irrelevant.

我的本地时区为UTC +01:00和夏季(今年)开始于2013年3月31日凌晨2点,其中时间调整为3:00

My Local timezone is UTC+01:00 and the summertime (this year) begins on 31.03.2013 2:00, where the time is adjusted to 3:00.

当我安排新利用所提出的触发器上可以说,2013年2月20日工作,石英计算System.DateTimeOffset为NextFireTimeUtc正确地:结果
日期时间:2013年3月1日13时00分零零秒(这是UTC时间,这背后是当地时区一小时)结果
LocalDateTime:2013年3月1日14时00分00秒。

When i schedule a new Job using the proposed trigger on lets say 20.02.2013, Quartz calculates the System.DateTimeOffset for the "NextFireTimeUtc" correctly to:
DateTime: 01.03.2013 13:00:00 (this is the UTC time, which is one hour behind the local timezone)
LocalDateTime: 01.03.2013 14:00:00

作业将正确地触发14时00分。小时,指定

The job will correctly trigger on 14:00 hours as specified.

现在,如果我安排在2013年3月20日的工作中,NextFireTimeUtc结果:结果
日期时间:2013年4月1日13 :00:00(这是UTC时间,也就是现在后面的本地时区的两小时)结果
LocalDateTime:2013年4月1日的 15:00:00

Now if i schedule the job on 20.03.2013, the "NextFireTimeUtc" results in:
DateTime: 01.04.2013 13:00:00 (this is the UTC time, which is now two hours behind the local timezone)
LocalDateTime: 01.04.2013 15:00:00

请注意,所产生的NextFireTimeUtc目前当地夏季内。其结果是,该LocalDateTime也被从UTC一小时校正。这导致工作时间为15:00分,这不是我想要的运行。

Notice, that the resulting NextFireTimeUtc now falls within the local summertime. As a result, the LocalDateTime was also "corrected" by an additional hour from the UTC. This results in the job running at 15:00 hours, which is not what i want.

我(显然)预期是什么,在cron表达式的14应该导致触发14:00射击,即使是在夏季。

What i (obviously) expected is that the "14" in the cron expression should always result in the trigger firing at 14:00, even during summertime.

必须有一个简单的方法来处理这​​个现象,我可能只是失去了一些东西概念性。我很困惑

There must be an easy way to deal with this phenomenon, i am probably just missing something conceptional. I am confused.

编辑:结果
的问题似乎是,石英计算的首先 NextFireTimeUtc取决于电流时区信息。为了测试这一点,我计划两个不同的cron触发器和对与越来越抵消过去一年来查看所产生的明火时代触发称为GetFireTimeAfter()


The problem seems to be, that Quartz calculates the first NextFireTimeUtc depending on the current timezone information. To test this, i scheduled two different cron triggers and called GetFireTimeAfter() on the trigger with an increasing offset to view the resulting fire times over the year.

触发1:消防在每月28日14:00

Trigger 1: Fire on the 28th of every month at 14:00

GetFireTimeAfter现在+ 00月:2013年3月28日的 13:00:00 +00:00 < - 这是正确的结果
GetFireTimeAfter现在+ 01月:2013年4月28日12时零零分00秒+00:00结果
GetFireTimeAfter现在+ 02月:2013年5月28日12时○○分00秒+00:00结果
GetFireTimeAfter现在+ 03个月:2013年6月28日12时○○分00秒+00:00结果
GetFireTimeAfter现在+ 04月:2013年7月28日12时○○分00秒+00:00结果
GetFireTimeAfter现在+ 05个月:2013年8月28日12时○○分00秒+00:00结果
GetFireTimeAfter现在+ 06月:2013年9月28日12:00:00 +00:00结果
GetFireTimeAfter现在+ 07个月:2013年10月28日13:00:00 +00:00< - 夏季已经结束结果$ b现在08 + $ b GetFireTimeAfter个月:2013年11月28日13:00:00 +00:00

GetFireTimeAfter now + 00 months: 28.03.2013 13:00:00 +00:00 <- this is correct
GetFireTimeAfter now + 01 months: 28.04.2013 12:00:00 +00:00
GetFireTimeAfter now + 02 months: 28.05.2013 12:00:00 +00:00
GetFireTimeAfter now + 03 months: 28.06.2013 12:00:00 +00:00
GetFireTimeAfter now + 04 months: 28.07.2013 12:00:00 +00:00
GetFireTimeAfter now + 05 months: 28.08.2013 12:00:00 +00:00
GetFireTimeAfter now + 06 months: 28.09.2013 12:00:00 +00:00
GetFireTimeAfter now + 07 months: 28.10.2013 13:00:00 +00:00 <- summertime already ended
GetFireTimeAfter now + 08 months: 28.11.2013 13:00:00 +00:00

第一次起火是正确的,因为它仍然属于冬天。 夏季期间,时间是关闭的一个额外的-1,导致火灾正确的时间在本地时区增加后+2

The first fire time is correct, since it still falls into "wintertime". The times during "summertime" are off by an additional -1, resulting in the correct fire time after the local timezone adds +2.

触发器1:火上的第一个在14:00每月的日

Trigger 1: Fire on the first day of every month at 14:00

GetFireTimeAfter现在+ 00月:2013年4月1日的 13:00:00 +00: 00 < - 这是错误的结果
GetFireTimeAfter现在+ 01月:2013年1月5日12:00:00 +00:00结果
GetFireTimeAfter现在+ 02月:? 2013年6月1日12:00:00 +00:00结果
GetFireTimeAfter现在+ 03月:2013年1月7日12:00:00 +00:00结果
GetFireTimeAfter现在+ 04月: 2013年1月8日十二时00分00秒+00:00结果
GetFireTimeAfter现在+ 05月:2013年9月1日十二时00分00秒+00:00结果
GetFireTimeAfter现在+ 06月: 2013年10月1日十二时00分00秒+00:00结果
GetFireTimeAfter现在+ 07月:2013年11月1日13点○○分00秒+00:00< - 夏季已经结束结果
GetFireTimeAfter现在+ 08月:二零一三年十二月一日13:00:00 +00:00

GetFireTimeAfter now + 00 months: 01.04.2013 13:00:00 +00:00 <- this is wrong?
GetFireTimeAfter now + 01 months: 01.05.2013 12:00:00 +00:00
GetFireTimeAfter now + 02 months: 01.06.2013 12:00:00 +00:00
GetFireTimeAfter now + 03 months: 01.07.2013 12:00:00 +00:00
GetFireTimeAfter now + 04 months: 01.08.2013 12:00:00 +00:00
GetFireTimeAfter now + 05 months: 01.09.2013 12:00:00 +00:00
GetFireTimeAfter now + 06 months: 01.10.2013 12:00:00 +00:00
GetFireTimeAfter now + 07 months: 01.11.2013 13:00:00 +00:00 <- summertime already ended
GetFireTimeAfter now + 08 months: 01.12.2013 13:00:00 +00:00

的第一把火已经消夏之内,但其仅由-1偏移,导致在15:00的本地触发时间。

The first fire already falls within summertime, but its only offset by -1, resulting in a local trigger time of 15:00.

所以触发器是好的,除了第触发时间,如果在冬季调度和第一次执行落在夏季之内。如何处理?

So the trigger is fine, except for the first trigger time, if its scheduled during wintertime and the first execution falls within summertime. How to handle this?

推荐答案

我想通了,这实际上是在Quartz.NET 2.0.1中的错误,但它有已被固定在2.1.0。

I figured out that this actually is a bug in Quartz.NET 2.0.1, but it has already been fixed in 2.1.0.

请参阅这个答案了解详情。

这篇关于Quartz.NET - 使用/ cron的理解基于触发器和时区/夏令时(夏令时间)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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