我在单独的循环迭代中生成两组重复事件,但是在比较生成的冲突结果时会出现冲突。这似乎是在时代倒退的时候,我不知道如何解决这个问题?
第一个重复事件将:
第二个重复事件将:
为了生成事件,我每天在当地时区“欧洲/斯德哥尔摩”中循环使用这样的Nodatime:
String timeZone = "Europe/Stockholm";
for (ZonedDateTime date_Local = repeatSeriesStartDate_Local; date_Local <= LoopEndDate_Local; date_Local = new ZonedDateTime(Instant.FromDateTimeUtc(date_Local.ToDateTimeUtc().AddDays(1).ToUniversalTime()),timeZone))我的问题出现在2016年10月29日/30日,当时时钟倒转,第二条规则与第一条规则发生冲突。http://www.timeanddate.com/time/change/sweden/stockholm?year=2016
冲突时间如下:
我使用这样的算法来测试冲突https://stackoverflow.com/a/325964/884132
我该如何处理这些时间转移的冲突?
发布于 2015-11-03 18:33:30
如果你能澄清这个问题,这真的会有帮助,但我现在要做几个假设。如果有必要,我可以稍后编辑这个问题。
你可能想做的是这样的事情:
for (LocalDate date = startDate; date <= endDate; date = date.PlusDays(1))
{
ZonedDateTime zdt = date.At(eventTime).InZone(tz, SchedulingResolver);
Console.WriteLine(zdt); // or whatever you want to do from here
}SchedulingResolver实现是这里,只有在使用Noda的1.x版本时才有必要。如果使用的是2.x,则只需使用InZoneLeniently(tz),因为2.x中宽大解析器的行为已更改为匹配(请参阅2.x迁移指南中的“宽大解析器更改”)。
要点是:
ZonedDateTime通常最好用作中介类型。- You have daily events that are based on the local day, so `LocalDate` is more appropriate.
- If you had events based on a fixed 24-hour rotation (aka, the UTC day), then `Instant` would be more appropriate.
LocalDateTime值映射回特定时刻。我推荐用于调度目的的解析器是:- Advances by the DST bias (usually 1 hour) when the clocks go forward (spring)
- Picks the first instance when the clocks go back (fall)
虽然正如乔恩提到的--你的需求可能会有所不同,但我们真的不能回答你该做什么。的确,有些业务需要不同的解析规则,而不是我推荐的规则。
https://stackoverflow.com/questions/33502878
复制相似问题