From e226825bdea9d698752305b371daa1a4ebba66aa Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Tue, 17 Feb 2015 16:05:50 -0500 Subject: [PATCH] Add [NSCalendarDate+SOGo iso8601DateString] --- SoObjects/SOGo/NSCalendarDate+SOGo.h | 1 + SoObjects/SOGo/NSCalendarDate+SOGo.m | 30 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/SoObjects/SOGo/NSCalendarDate+SOGo.h b/SoObjects/SOGo/NSCalendarDate+SOGo.h index de31ca69a..c57cd80e6 100644 --- a/SoObjects/SOGo/NSCalendarDate+SOGo.h +++ b/SoObjects/SOGo/NSCalendarDate+SOGo.h @@ -37,6 +37,7 @@ - (NSString *) shortDateString; - (NSString *) rfc822DateString; +- (NSString *) iso8601DateString; + (id) distantFuture; + (id) distantPast; diff --git a/SoObjects/SOGo/NSCalendarDate+SOGo.m b/SoObjects/SOGo/NSCalendarDate+SOGo.m index 4ba4cd4ed..2d496a2cc 100644 --- a/SoObjects/SOGo/NSCalendarDate+SOGo.m +++ b/SoObjects/SOGo/NSCalendarDate+SOGo.m @@ -21,6 +21,8 @@ #import #import +#import + #import #import "NSCalendarDate+SOGo.h" @@ -113,6 +115,34 @@ static NSString *rfc822Months[] = {@"", @"Jan", @"Feb", @"Mar", @"Apr", timeZoneShift]; } +- (NSString *) iso8601DateString +{ + char buf[22]; + int timeZoneHourShift, timeZoneMinuteShift, tzSeconds; + NSNumber *day, *month, *year, *hour, *minute; + + day = [NSNumber numberWithInt: [self dayOfMonth]]; + month = [NSNumber numberWithInt: [self monthOfYear]]; + year = [NSNumber numberWithInt: [self yearOfCommonEra]]; + hour = [NSNumber numberWithInt: [self hourOfDay]]; + minute = [NSNumber numberWithInt: [self minuteOfHour]]; + + tzSeconds = [[self timeZone] secondsFromGMT]; + timeZoneHourShift = (tzSeconds / 3600); + tzSeconds -= timeZoneHourShift * 3600; + timeZoneMinuteShift = tzSeconds / 60; + + sprintf(buf, "%04d-%02d-%02dT%02d:%02d%+.2d:%02d", + [year intValue], + [month intValue], + [day intValue], + [hour intValue], + [minute intValue], + timeZoneHourShift, + timeZoneMinuteShift); + + return [NSString stringWithCString:buf]; +} #define secondsOfDistantFuture 1073741823.0 #define secondsOfDistantPast -1073741823.0