From f58ab98f0d71ae481833ffcd6197085e7fe1ede3 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Thu, 7 Jun 2007 16:20:01 +0000 Subject: [PATCH] Monotone-Parent: 24cd0f4a54d77d53f8c9e4dc117f32e9a5c42d72 Monotone-Revision: 3330b71df0d8c44d51c1026cc042cc4c911cff1a Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2007-06-07T16:20:01 Monotone-Branch: ca.inverse.sogo --- SOPE/NGCards/ChangeLog | 4 ++++ SOPE/NGCards/NSString+NGCards.h | 1 + SOPE/NGCards/NSString+NGCards.m | 38 +++++++++++++++++++++++++++------ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/SOPE/NGCards/ChangeLog b/SOPE/NGCards/ChangeLog index 0d22b7c97..657305992 100644 --- a/SOPE/NGCards/ChangeLog +++ b/SOPE/NGCards/ChangeLog @@ -1,5 +1,9 @@ 2007-06-07 Wolfgang Sourdeau + * NSString+NGCards.m ([NSString -isAllDayDate]): new method that + determines whether the date represented in "self" is an all day + date (date only) or not (date + time). + * CardElement.h: moved IS_EQUAL macro from removed module "common.h". diff --git a/SOPE/NGCards/NSString+NGCards.h b/SOPE/NGCards/NSString+NGCards.h index 2b57059a2..0311ab6be 100644 --- a/SOPE/NGCards/NSString+NGCards.h +++ b/SOPE/NGCards/NSString+NGCards.h @@ -37,6 +37,7 @@ - (NSTimeInterval) durationAsTimeInterval; - (NSCalendarDate *) asCalendarDate; +- (BOOL) isAllDayDate; - (NSArray *) commaSeparatedValues; diff --git a/SOPE/NGCards/NSString+NGCards.m b/SOPE/NGCards/NSString+NGCards.m index 21cee5b57..a53378a5c 100644 --- a/SOPE/NGCards/NSString+NGCards.m +++ b/SOPE/NGCards/NSString+NGCards.m @@ -214,9 +214,11 @@ static NSString *commaSeparator = nil; NSRange cursor; NSCalendarDate *date; NSTimeZone *utc; + unsigned int length; int year, month, day, hour, minute, second; - if ([self length] > 14) + length = [self length]; + if (length > 7) { cursor = NSMakeRange(0, 4); year = [[self substringWithRange: cursor] intValue]; @@ -226,12 +228,21 @@ static NSString *commaSeparator = nil; cursor.location += cursor.length; day = [[self substringWithRange: cursor] intValue]; - cursor.location += cursor.length + 1; - hour = [[self substringWithRange: cursor] intValue]; - cursor.location += cursor.length; - minute = [[self substringWithRange: cursor] intValue]; - cursor.location += cursor.length; - second = [[self substringWithRange: cursor] intValue]; + if (length > 14) + { + cursor.location += cursor.length + 1; + hour = [[self substringWithRange: cursor] intValue]; + cursor.location += cursor.length; + minute = [[self substringWithRange: cursor] intValue]; + cursor.location += cursor.length; + second = [[self substringWithRange: cursor] intValue]; + } + else + { + hour = 0; + minute = 0; + second = 0; + } utc = [NSTimeZone timeZoneWithAbbreviation: @"GMT"]; date = [NSCalendarDate dateWithYear: year month: month @@ -245,6 +256,19 @@ static NSString *commaSeparator = nil; return date; } +- (BOOL) isAllDayDate +{ + unsigned int length; + unichar lastZ; + + length = [self length]; + lastZ = [self characterAtIndex: length - 1]; + + return (length == 8 + || (length == 9 + && (lastZ == 'Z' || lastZ == 'z'))); +} + - (NSArray *) commaSeparatedValues { NSEnumerator *rawValues;