diff --git a/SOPE/NGCards/ChangeLog b/SOPE/NGCards/ChangeLog index 0a88ead42..def66f899 100644 --- a/SOPE/NGCards/ChangeLog +++ b/SOPE/NGCards/ChangeLog @@ -1,3 +1,20 @@ +2008-07-14 Wolfgang Sourdeau + + * ICalDateHolder.m: removed class module. + + * NSCalendarDate+ICal.m ([NSCalendarDate + +calendarDateWithICalRepresentation:]): removed method. + + * iCalRecurrenceCalculator.m: no longer use the + calendarDateWithICalRepresentation: category method (removed), use + NSString's asCalendarDate category method instead. + + * iCalRepeatableEntityObject.m ([iCalRepeatableEntityObject + -classForTag:classTag]): instances of EXDATE are of iCalDateTime + class. + ([iCalRepeatableEntityObject -exceptionDates]): return the dates + as utc-based date strings. + 2008-07-11 Wolfgang Sourdeau * iCalEntityObject.m ([iCalEntityObject -setRecurrenceId:newRecId]) diff --git a/SOPE/NGCards/GNUmakefile b/SOPE/NGCards/GNUmakefile index 563c21346..a574802e3 100644 --- a/SOPE/NGCards/GNUmakefile +++ b/SOPE/NGCards/GNUmakefile @@ -71,7 +71,6 @@ libNGCards_OBJC_FILES = \ NSDictionary+NGCards.m \ NSString+NGCards.m \ NSCalendarDate+ICal.m \ - iCalDateHolder.m \ \ CardElement.m \ CardGroup.m \ diff --git a/SOPE/NGCards/NSCalendarDate+ICal.h b/SOPE/NGCards/NSCalendarDate+ICal.h index 1f10eac24..c61269680 100644 --- a/SOPE/NGCards/NSCalendarDate+ICal.h +++ b/SOPE/NGCards/NSCalendarDate+ICal.h @@ -28,8 +28,6 @@ @interface NSCalendarDate(iCalRepresentation) -+ (id)calendarDateWithICalRepresentation:(NSString *)_iCalRep; - /* represention */ - (NSString *)icalStringWithTimeZone:(NSTimeZone *)_tz; diff --git a/SOPE/NGCards/NSCalendarDate+ICal.m b/SOPE/NGCards/NSCalendarDate+ICal.m index bca9721f6..c2c89cce2 100644 --- a/SOPE/NGCards/NSCalendarDate+ICal.m +++ b/SOPE/NGCards/NSCalendarDate+ICal.m @@ -25,7 +25,6 @@ #import #import "NSCalendarDate+ICal.h" -#import "iCalDateHolder.h" static NSTimeZone *gmt = nil; static inline void _setupGMT(void) { @@ -33,27 +32,12 @@ static inline void _setupGMT(void) { gmt = [[NSTimeZone timeZoneWithAbbreviation:@"GMT"] retain]; } -@interface iCalDateHolder (PrivateAPI) -- (id)awakeAfterUsingSaxDecoder:(id)_decoder; -@end - @implementation NSCalendarDate(iCalRepresentation) /* represention */ static NSString *gmtcalfmt = @"%Y%m%dT%H%M%SZ"; -+ (id)calendarDateWithICalRepresentation:(NSString *)_iCalRep { - iCalDateHolder *dh; - NSCalendarDate *date; - - dh = [[iCalDateHolder alloc] init]; - [dh setString:_iCalRep]; - date = [dh awakeAfterUsingSaxDecoder:nil]; - [dh release]; - return date; -} - - (NSString *)icalStringInGMT { NSTimeZone *oldtz; NSString *s; diff --git a/SOPE/NGCards/iCalDateHolder.h b/SOPE/NGCards/iCalDateHolder.h deleted file mode 100644 index fa6202730..000000000 --- a/SOPE/NGCards/iCalDateHolder.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - Copyright (C) 2000-2005 SKYRIX Software AG - - This file is part of SOPE. - - SOPE is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by the - Free Software Foundation; either version 2, or (at your option) any - later version. - - SOPE is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with SOPE; see the file COPYING. If not, write to the - Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. -*/ - -#ifndef __NGiCal_iCalDateHolder_H__ -#define __NGiCal_iCalDateHolder_H__ - -#import - -@class NSString, NSTimeZone; - -@interface iCalDateHolder : NSObject -{ - NSString *tzid; - NSString *string; - NSString *tag; -} - -- (void)setString:(NSString *)_value; -- (NSString *)string; - -- (void)setTag:(NSString *)_value; -- (NSString *)tag; - -- (void)setTzid:(NSString *)_value; -- (NSString *)tzid; - -- (NSTimeZone *)timeZone; - -@end - -#endif /* __NGiCal_iCalDateHolder_H__ */ diff --git a/SOPE/NGCards/iCalDateHolder.m b/SOPE/NGCards/iCalDateHolder.m deleted file mode 100644 index 7115447c8..000000000 --- a/SOPE/NGCards/iCalDateHolder.m +++ /dev/null @@ -1,243 +0,0 @@ -/* - Copyright (C) 2000-2005 SKYRIX Software AG - - This file is part of SOPE. - - SOPE is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by the - Free Software Foundation; either version 2, or (at your option) any - later version. - - SOPE is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with SOPE; see the file COPYING. If not, write to the - Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. -*/ - -#import -#import -#import -#import -#import - -#import -#import - -#import "iCalDateHolder.h" -#import "iCalObject.h" - -@interface NSTimeZone(iCalTimeZone) - -+ (NSTimeZone *)timeZoneWithICalId:(NSString *)_tz; - -@end - -@implementation iCalDateHolder - -static NSTimeZone *gmt = nil; - -+ (void)initialize { - if (gmt == nil) - gmt = [[NSTimeZone timeZoneWithName:@"GMT"] retain]; -} - -- (void)dealloc { - [self->tzid release]; - [self->string release]; - [self->tag release]; - [super dealloc]; -} - -/* accessors */ - -- (void)setString:(NSString *)_value { - ASSIGNCOPY(self->string, _value); -} -- (NSString *)string { - return self->string; -} - -- (void)setTag:(NSString *)_value { - ASSIGNCOPY(self->tag, _value); -} -- (NSString *)tag { - return self->tag; -} - -- (void)setTzid:(NSString *)_value { - ASSIGNCOPY(self->tzid, _value); -} -- (NSString *)tzid { - return self->tzid; -} - -/* mapping to Foundation */ - -- (NSTimeZone *)timeZone { - // TODO: lookup tzid in iCalCalendar ! - NSString *s; - - s = [self tzid]; - - /* a hack */ - if ([s hasPrefix:@"/softwarestudio.org"]) { - NSRange r; - - r = [s rangeOfString:@"Europe/"]; - if (r.length > 0) - s = [s substringFromIndex:r.location]; - } - return [NSTimeZone timeZoneWithICalId:s]; -} - -/* decoding */ - -- (id)awakeAfterUsingSaxDecoder:(id)_decoder { - NSCalendarDate *date = nil; - NSString *s; - NSTimeZone *tz; - - s = self->string; - if ([s length] < 5) { - [self logWithFormat:@"tag %@: got an weird date string '%@' ?!", - self->tag, s]; - return s; - } - - /* calculate timezone */ - - if ([self->string hasSuffix:@"Z"]) { - /* zulu time, eg 20021009T094500Z */ - tz = gmt; - s = [s substringToIndex:([s length] - 1)]; - } - else - tz = [self timeZone]; - - /* - 012345678901234 - 20021009T094500 - 15 chars - 20021009T0945 - 13 chars - 991009T0945 - 11 chars - - 20031111 - 8 chars - */ - if ([s rangeOfString:@"T"].length == 0 && [s length] == 8) { - /* hm, maybe a date without a time? like an allday event! */ - int year, month, day; - char *buf; - - buf = strdup([s cStringUsingEncoding: NSASCIIStringEncoding]); - - day = atoi(buf + 6); - buf[6] = '\0'; - month = atoi(buf + 4); - buf[4] = '\0'; - year = atoi(buf); - free (buf); - - date = [NSCalendarDate dateWithYear:year month:month day:day - hour:0 minute:0 second:0 - timeZone:tz]; - } - else if ([s length] == 15) { - int year, month, day, hour, minute, second; - char buf[24]; - [s getCString:&(buf[0])]; - - second = atoi(&(buf[13])); buf[13] = '\0'; - minute = atoi(&(buf[11])); buf[11] = '\0'; - hour = atoi(&(buf[9])); buf[9] = '\0'; - day = atoi(&(buf[6])); buf[6] = '\0'; - month = atoi(&(buf[4])); buf[4] = '\0'; - year = atoi(&(buf[0])); - - date = [NSCalendarDate dateWithYear:year month:month day:day - hour:hour minute:minute second:second - timeZone:tz]; - } - else - NSLog(@"%s: unknown date format (%@) ???", __PRETTY_FUNCTION__, s); - - if (date == nil) - NSLog(@"couldn't convert string '%@' to date (format '%@') ..", s); - - return date; -} - -/* description */ - -- (void)appendAttributesToDescription:(NSMutableString *)ms { - if (self->tag) [ms appendFormat:@" %@", self->tag]; - if (self->string) [ms appendFormat:@" '%@'", self->string]; - if (self->tzid) [ms appendFormat:@" tz=%@", self->tzid]; -} - -- (NSString *)description { - NSMutableString *ms; - - ms = [NSMutableString stringWithCapacity:128]; - [ms appendFormat:@"<0x%p[%@]:", self, NSStringFromClass([self class])]; - [self appendAttributesToDescription:ms]; - [ms appendString:@">"]; - return ms; -} - -@end /* iCalDateHolder */ - -@implementation NSTimeZone(iCalTimeZone) - -static NSMutableDictionary *idToTz = nil; // THREAD - -+ (NSTimeZone *)timeZoneWithICalId:(NSString *)_tzid { - static NSString *iCalDefaultTZ = nil; - NSTimeZone *tz; - - if (idToTz == nil) - idToTz = [[NSMutableDictionary alloc] initWithCapacity:16]; - - if ([_tzid length] == 0) { - - tz = [iCalObject iCalDefaultTimeZone]; - if (tz != nil) return tz; - - if (iCalDefaultTZ == nil) { - NSString *defTz; - NSUserDefaults *ud; - // TODO: take a default timeZone - ud = [NSUserDefaults standardUserDefaults]; - defTz = [ud stringForKey:@"iCalTimeZoneName"]; - if ([defTz length] == 0) - defTz = [ud stringForKey:@"TimeZoneName"]; - if ([defTz length] == 0) - defTz = [ud stringForKey:@"TimeZone"]; - if ([defTz length] == 0) - defTz = @"GMT"; - iCalDefaultTZ = [defTz retain]; - } - - _tzid = iCalDefaultTZ; - - } - - if ([_tzid length] == 0) - _tzid = @"GMT"; - - tz = [idToTz objectForKey:_tzid]; - if (tz == nil) tz = [NSTimeZone timeZoneWithName:_tzid]; - if (tz == nil) tz = [NSTimeZone timeZoneWithAbbreviation:_tzid]; - - if (tz == nil) { - NSLog(@"couldn't map timezone id %@", _tzid); - } - - if (tz) [idToTz setObject:tz forKey:_tzid]; - return tz; -} - -@end /* NSTimeZone(iCalTimeZone) */ diff --git a/SOPE/NGCards/iCalRecurrenceCalculator.m b/SOPE/NGCards/iCalRecurrenceCalculator.m index b22bc45c8..66a06ec65 100644 --- a/SOPE/NGCards/iCalRecurrenceCalculator.m +++ b/SOPE/NGCards/iCalRecurrenceCalculator.m @@ -27,8 +27,7 @@ #import #import "iCalRecurrenceRule.h" -#import "NSCalendarDate+ICal.h" - +#import "NSString+NGCards.h" #import "iCalRecurrenceCalculator.h" @@ -173,9 +172,7 @@ static Class yearlyCalcClass = Nil; while ((currentDate = [dates nextObject])) { if ([currentDate isKindOfClass: NSStringClass]) - currentDate - = [NSCalendarDate - calendarDateWithICalRepresentation: (NSString *) currentDate]; + currentDate = [(NSString *) currentDate asCalendarDate]; if ([limits containsDate: currentDate]) [newDates addObject: currentDate]; } diff --git a/SOPE/NGCards/iCalRepeatableEntityObject.m b/SOPE/NGCards/iCalRepeatableEntityObject.m index 90d1183bf..dc52aa950 100644 --- a/SOPE/NGCards/iCalRepeatableEntityObject.m +++ b/SOPE/NGCards/iCalRepeatableEntityObject.m @@ -26,6 +26,8 @@ #import +#import "NSCalendarDate+NGCards.h" +#import "iCalDateTime.h" #import "iCalRecurrenceRule.h" #import "iCalRecurrenceCalculator.h" #import "iCalRepeatableEntityObject.h" @@ -38,6 +40,8 @@ if ([classTag isEqualToString: @"RRULE"]) tagClass = [iCalRecurrenceRule class]; + else if ([classTag isEqualToString: @"EXDATE"]) + tagClass = [iCalDateTime class]; else tagClass = [super classForTag: classTag]; @@ -121,7 +125,21 @@ - (NSArray *) exceptionDates { - return [self childrenWithTag: @"exdate"]; + NSMutableArray *dates; + NSEnumerator *dateList; + NSCalendarDate *exDate; + NSString *dateString; + + dates = [NSMutableArray array]; + dateList = [[self childrenWithTag: @"exdate"] objectEnumerator]; + while ((exDate = [[dateList nextObject] dateTime])) + { + dateString = [NSString stringWithFormat: @"%@Z", + [exDate iCalFormattedDateTimeString]]; + [dates addObject: dateString]; + } + + return dates; } /* Convenience */