Add [NSCalendarDate+SOGo iso8601DateString]

This commit is contained in:
Francis Lachapelle
2015-02-17 16:05:50 -05:00
parent d8a816a335
commit e226825bde
2 changed files with 31 additions and 0 deletions
+1
View File
@@ -37,6 +37,7 @@
- (NSString *) shortDateString;
- (NSString *) rfc822DateString;
- (NSString *) iso8601DateString;
+ (id) distantFuture;
+ (id) distantPast;
+30
View File
@@ -21,6 +21,8 @@
#import <Foundation/NSCalendarDate.h>
#import <Foundation/NSTimeZone.h>
#import <Foundation/NSValue.h>
#import <NGExtensions/NSCalendarDate+misc.h>
#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