Closed GoogleCodeExporter closed 9 years ago
The NSCalendarDate ISO8601 category is really overkill besides. The xsd:dateTime
format is a tiny subset of the general ISO8601 format.
http://www.w3.org/TR/xmlschema-2/#isoformats
The easiest solution to this issue is to remove the NSCalendarDate category,
switch
the type for xsd:dateTime to NSDate, and do something along these lines in
USAdditions (this is untested because I'm having other troubles getting this
tool to
work).
@implementation NSDate (USAdditions)
static NSDateFormatter *kUSdateFormat = @"uuuu-MM-dd'T'HH:mm:ss";
- (NSString *)serializedFormUsingElementName:(NSString *)elName
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:kUSdateFormat];
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
NSString *result = [NSString stringWithFormat:@"<%@>%@Z</%@>", elName,
[dateFormatter stringFromDate:self], elName];
[dateFormatter release];
return result;
}
+ (NSDate *)deserializeNode:(xmlNodePtr)cur
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:kUSdateFormat];
NSMutableString *dateString = [[NSString deserializeNode:cur] mutableCopy];
NSTimeZone *timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
if ([dateString characterAtIndex:[dateString length] - 1] == 'Z')
{
[dateString deleteCharactersInRange:NSMakeRange([dateString length] - 1, 1)];
}
else
{
NSString *offsetString = [dateString substringFromIndex:[dateString length] - 6];
unichar sign = [offsetString characterAtIndex:0];
if (sign == '+' || sign == '-')
{
NSInteger hours = [[offsetString substringToIndex:3] integerValue];
NSInteger minutes = [[offsetString substringFromIndex:5] integerValue];
NSInteger offsetSeconds = (hours * 60 + minutes) * 60;
timeZone = [NSTimeZone timeZoneForSecondsFromGMT:offsetSeconds];
[dateString deleteCharactersInRange:NSMakeRange([dateString length] - 6, 6)];
}
else
{
// There's no timezone, which is illegal, but we'll assume UTC.
}
}
[dateFormatter setTimeZone:timeZone];
NSDate *result = [isoDateFormatter dateFromString:dateString];
[dateFormatter release];
return result;
}
@end
Original comment by robnapier@gmail.com
on 7 Jan 2009 at 1:59
I have fixed this, but cannot find out how to contact the project owner to join
the project to upload the fixes. If
you know how, let me know...
Original comment by goo...@faupel.org
on 15 Jun 2009 at 3:28
Check out the iPhone branch.
Thanks to faupel, it now works.
There are still wsdls that fail the parsing but I'm working on it.
Original comment by hasse...@gmail.com
on 5 Sep 2009 at 5:04
Original issue reported on code.google.com by
newintel...@gmail.com
on 14 Nov 2008 at 2:44