Daylight Saving Time Bug in EventKit

℡╲_俬逩灬. 提交于 2019-12-24 09:27:08

问题


I discovered a bug in eventKit where dates are altered when saving. In this sample, I use an event with title Midnight that is a 1 second long event calculated to be local astronomical midnight. In the local timeZone, there are two occurrences of 1AM to 2AM in locale format because of daylight saving time ending. The event occurs in the second instance of 1AM to 2AM. See this sample code:

if ([event.title containsString:@"Midnight"]) {
    NSLog(@"Timezone is %@",[NSTimeZone localTimeZone]);
    NSLog(@"Saving midnight from %@ to %@", event.startDate,event.endDate);
    NSLog(@"Saving midnight from %@ to %@", [event.startDate debugDescription],[event.endDate debugDescription]);
}
[self.eventStort saveEvent:event span:EKSpanThisEvent error:&error];
if ([event refresh]) {
    NSLog(@"Updated event goes from %@ to %@", event.startDate,event.endDate);
    NSLog(@"Updated event goes from %@ to %@", [event.startDate debugDescription],[event.endDate debugDescription]);
}

Timezone is Local Time Zone (America/Chicaco (CST) offset -21600)
Saving midnight from Sun Nov  5 01:53:14 2017 to Sun Nov  5 01:53:15 2017
Saving midnight from 2017-11-05 07:53:14 +0000 to 2017-11-05 07:53:15 +0000
Updated event goes from Sun Nov  5 01:53:14 2017 to Sun Nov  5 01:53:15 2017
Updated event goes from 2017-11-05 07:53:14 +0000 to 2017-11-05 06:53:15 +0000

Notice that on the last line, the end date is one hour earlier immediately after the save. When displayed using the locale format, it looks the same, but looking at the UT date, you can tell it has changed.

In this particular example, with an event that is 1 second long, the result is an event where the start date is after the end date.

来源:https://stackoverflow.com/questions/47139246/daylight-saving-time-bug-in-eventkit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!