Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode CalEvent与iCal和my app的开始日期和结束日期差异_Xcode_Cocoa_Nsdate_Icalendar_Calendar Store - Fatal编程技术网

Xcode CalEvent与iCal和my app的开始日期和结束日期差异

Xcode CalEvent与iCal和my app的开始日期和结束日期差异,xcode,cocoa,nsdate,icalendar,calendar-store,Xcode,Cocoa,Nsdate,Icalendar,Calendar Store,如果我在ICal上创建了一个新事件,并将其设置为全天事件,则我的应用程序显示它将持续2天 我使用nslog输出startdate和enddate,对于2012年5月8日的事件,我的应用程序显示事件将于2012年5月9日21:00(晚上9点)结束 这是什么原因造成的?将应用程序中的开始/结束日期转换为iCal上显示的相同值的最佳方式是什么。问题只存在于全天活动中。根据这一点: if([event isAllDay]) { //从技术上讲,全天的活动范围从00:00到00:00,即使 //我们希望它

如果我在ICal上创建了一个新事件,并将其设置为全天事件,则我的应用程序显示它将持续2天

我使用nslog输出startdate和enddate,对于2012年5月8日的事件,我的应用程序显示事件将于2012年5月9日21:00(晚上9点)结束

这是什么原因造成的?将应用程序中的开始/结束日期转换为iCal上显示的相同值的最佳方式是什么。问题只存在于全天活动中。

根据这一点:

if([event isAllDay])
{
//从技术上讲,全天的活动范围从00:00到00:00,即使
//我们希望它们仅显示为从到的范围
NSDate*endDateMinusOneDay=dateByAddingDays([event endDate],-1);
NSInteger daysDiff=getDayDiff([event startDate],endDateMinusOneDay);
如果(daysDiff>0)
{
elements.value=M_ATTR_STR((
strConcat(
dateStr([event startDate],仅限日期),
@" - ",
dateStr(endDateMinusOneDay,仅限_日期),
无
)
));
}

它应该是这样的,我需要处理它。时间的问题(21.00/9.00 pm)可能只是时区的差异,即使-这不重要。

好的。这里我做了一些函数,这样其他人就可以很容易地得到一些帮助

- (NSDate *)changeDayBy:(NSDate *)current:(NSUInteger) change
{
    NSDateComponents *components = [[[NSDateComponents alloc] init] autorelease];
    [components setDay: change];
    return [[NSCalendar currentCalendar] dateByAddingComponents:components toDate:current options:0];
}

- (BOOL) endDateNeedsAFix:(CalEvent *)event
    {
        if ( !event.isAllDay )
            return NO;

        NSDateComponents *comps1 = [[NSCalendar currentCalendar] components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:event.startDate] ;
        NSDateComponents *comps2 = [[NSCalendar currentCalendar] components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:event.endDate];

        return [[[NSCalendar currentCalendar] dateFromComponents: comps2] timeIntervalSinceDate: [[NSCalendar currentCalendar] dateFromComponents: comps1]] / ( 60*60*24) > 0 ? YES : NO;

    }

    - (NSDate*) endDateFixed:(CalEvent *)event
    {
        if ( !event.isAllDay )
            return event.endDate;

        NSDateComponents *comps1 = [[NSCalendar currentCalendar] components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:event.startDate];
        NSDateComponents *comps2 = [[NSCalendar currentCalendar] components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:event.endDate];

        if ( [[[NSCalendar currentCalendar] dateFromComponents: comps2] timeIntervalSinceDate: [[NSCalendar currentCalendar] dateFromComponents: comps1]] / ( 60*60*24) > 0 )
            return [self changeDayBy:event.endDate :-1];

        return event.endDate;
    }
函数endDateNeedsAFix报告所选calEvent*事件是否需要修复。如果应用程序具有某种类型的事件编辑器,其中显示的结束日期是固定的,这将非常有用。在保存更改之前,请检查是否需要修复,然后使用changeDayBy将+1添加到日期


endDateFixed从事件的endDate返回NSDate-如果没有必要,则为不变-但如果需要,则为固定值。

查看了ical和应用程序之间时区的差异吗?
- (NSDate *)changeDayBy:(NSDate *)current:(NSUInteger) change
{
    NSDateComponents *components = [[[NSDateComponents alloc] init] autorelease];
    [components setDay: change];
    return [[NSCalendar currentCalendar] dateByAddingComponents:components toDate:current options:0];
}

- (BOOL) endDateNeedsAFix:(CalEvent *)event
    {
        if ( !event.isAllDay )
            return NO;

        NSDateComponents *comps1 = [[NSCalendar currentCalendar] components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:event.startDate] ;
        NSDateComponents *comps2 = [[NSCalendar currentCalendar] components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:event.endDate];

        return [[[NSCalendar currentCalendar] dateFromComponents: comps2] timeIntervalSinceDate: [[NSCalendar currentCalendar] dateFromComponents: comps1]] / ( 60*60*24) > 0 ? YES : NO;

    }

    - (NSDate*) endDateFixed:(CalEvent *)event
    {
        if ( !event.isAllDay )
            return event.endDate;

        NSDateComponents *comps1 = [[NSCalendar currentCalendar] components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:event.startDate];
        NSDateComponents *comps2 = [[NSCalendar currentCalendar] components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:event.endDate];

        if ( [[[NSCalendar currentCalendar] dateFromComponents: comps2] timeIntervalSinceDate: [[NSCalendar currentCalendar] dateFromComponents: comps1]] / ( 60*60*24) > 0 )
            return [self changeDayBy:event.endDate :-1];

        return event.endDate;
    }