这个问题与这个问题有关,但更笼统,可以独立处理。
编辑:石英版本是 v2.0.1
据我了解,以下单元测试应该通过:
[Test]
public void Test() {
// run every first day of month at 14:00 hours
CronExpression expression = new CronExpression("0 0 14 1 * ?");
// TimeZoneInfo.Local = {(UTC+01:00) Amsterdam, Berlin, Bern, Rom, Stockholm, Wien}
if (!TimeZoneInfo.Local.SupportsDaylightSavingTime) {
return;
}
// get "summertime" period for current timezone
var daylightChange = TimeZone.CurrentTimeZone.GetDaylightChanges(2013);
// -> daylightChange.Start {31.03.2013 02:00:00} System.DateTime
// -> daylightChange.End {27.10.2013 03:00:00} System.DateTime
// get one startpoint before and one after begin of summertime
DateTimeOffset beforeSummertime = daylightChange.Start.ToUniversalTime().AddDays(-1);
DateTimeOffset afterSummertime = daylightChange.Start.ToUniversalTime().AddDays(1);
// -> beforeSummertime {30.03.2013 01:00:00 +00:00} System.DateTimeOffset
// -> afterSummertime {01.04.2013 01:00:00 +00:00} System.DateTimeOffset
DateTimeOffset? nextValidTimeFromBefore = expression.GetNextValidTimeAfter(beforeSummertime);
DateTimeOffset? nextValidTimeFromAfter = expression.GetNextValidTimeAfter(afterSummertime);
// nextValidTimeFromBefore {01.04.2013 13:00:00 +00:00} System.DateTimeOffset?
// nextValidTimeFromAfter {01.04.2013 12:00:00 +00:00} System.DateTimeOffset?
Assert.AreEqual(nextValidTimeFromBefore, nextValidTimeFromAfter);
}
但是(如您所见),nextValidTimeFromBefore
不同于nextValidTimeFromAfter
. 结果nextValidTimeFromAfter
是正确的。UTC 12:00 将导致夏季时间为 14:00(此时已经开始)。GetNextValidTimeAfter()
参数指定夏令时内部还是外部的时间无关紧要。
NextValidTimes 应该相等还是我的方法有缺陷?