Frameworks/AIUtilities Framework/Source/NSCalendarDate+ISO8601Unparsing.m
branchadium-1.5.9
changeset 5749 1521cab508bf
parent 5722 4ae85ad012cd
equal deleted inserted replaced
5726:44b2eacffae5 5749:1521cab508bf
    38 @implementation NSCalendarDate(ISO8601Unparsing)
    38 @implementation NSCalendarDate(ISO8601Unparsing)
    39 
    39 
    40 #pragma mark Public methods
    40 #pragma mark Public methods
    41 
    41 
    42 - (NSString *)ISO8601DateStringWithTime:(BOOL)includeTime timeSeparator:(unichar)timeSep {
    42 - (NSString *)ISO8601DateStringWithTime:(BOOL)includeTime timeSeparator:(unichar)timeSep {
    43 	NSString *dateFormat = [(includeTime ? @"%Y-%m-%dT%H:%M:%S" : @"%Y-%m-%d") prepareDateFormatWithTimeSeparator:timeSep];
    43 	NSString *dateFormat = [(includeTime ? @"yyyy'-'MM'-'dd'T'HH':'mm':'ss" : @"yyyy'-'MM'-'dd") prepareDateFormatWithTimeSeparator:timeSep];
    44 	NSDateFormatter *formatter = [[NSDateFormatter alloc] initWithDateFormat:dateFormat allowNaturalLanguage:NO];
    44 	NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    45 	[formatter setFormatterBehavior:NSDateFormatterBehavior10_4];
    45 	formatter.dateFormat = dateFormat;
    46 	NSString *str = [formatter stringForObjectValue:self];
    46 	NSString *str = [formatter stringFromDate:self];
    47 	[formatter release];
    47 	[formatter release];
    48 	if(includeTime) {
    48 	if(includeTime) {
    49 		NSInteger offset = [[self timeZone] secondsFromGMT];
    49 		NSInteger offset = [[self timeZone] secondsFromGMT];
    50 		offset /= 60;  //bring down to minutes
    50 		offset /= 60;  //bring down to minutes
    51 		if(offset == 0)
    51 		if(offset == 0)
   104 		}
   104 		}
   105 	}
   105 	}
   106 
   106 
   107 	NSString *timeString;
   107 	NSString *timeString;
   108 	if(includeTime) {
   108 	if(includeTime) {
   109 		NSDateFormatter *formatter = [[NSDateFormatter alloc] initWithDateFormat:[@"T%H:%M:%S%z" prepareDateFormatWithTimeSeparator:timeSep] allowNaturalLanguage:NO];
   109 		NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
   110 		[formatter setFormatterBehavior:NSDateFormatterBehavior10_4];
   110 		formatter.dateFormat = [@"'T'HH':'mm':'ssZ" prepareDateFormatWithTimeSeparator:timeSep];
   111 		timeString = [formatter stringForObjectValue:self];
   111 		timeString = [formatter stringForObjectValue:self];
   112 		[formatter release];
   112 		[formatter release];
   113 	} else
   113 	} else
   114 		timeString = @"";
   114 		timeString = @"";
   115 
   115 
   116 	return [NSString stringWithFormat:@"%u-W%02u-%02u%@", year, week, dayOfWeek + 1U, timeString];
   116 	return [NSString stringWithFormat:@"%u-W%02u-%02u%@", year, week, dayOfWeek + 1U, timeString];
   117 }
   117 }
   118 - (NSString *)ISO8601OrdinalDateStringWithTime:(BOOL)includeTime timeSeparator:(unichar)timeSep {
   118 - (NSString *)ISO8601OrdinalDateStringWithTime:(BOOL)includeTime timeSeparator:(unichar)timeSep {
   119 	NSString *timeString;
   119 	NSString *timeString;
   120 	if(includeTime) {
   120 	if(includeTime) {
   121 		NSDateFormatter *formatter = [[NSDateFormatter alloc] initWithDateFormat:[@"T%H:%M:%S%z" prepareDateFormatWithTimeSeparator:timeSep] allowNaturalLanguage:NO];
   121 		NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
   122 		[formatter setFormatterBehavior:NSDateFormatterBehavior10_4];
   122 		formatter.dateFormat = [@"'T'HH':'mm':'ssZ" prepareDateFormatWithTimeSeparator:timeSep];
   123 		timeString = [formatter stringForObjectValue:self];
   123 		timeString = [formatter stringForObjectValue:self];
   124 		[formatter release];
   124 		[formatter release];
   125 	} else
   125 	} else
   126 		timeString = @"";
   126 		timeString = @"";
   127 
   127