I have change the code in NSXMLElement+XEP_0203.m as followings:
- (NSDate *)delayedDeliveryDate
{
NSDate* currentTime = [NSDate date];
NSXMLElement *delay;
// From XEP-0203 (Delayed Delivery)
//
// <delay xmlns='urn:xmpp:delay'
// from='juliet@capulet.com/balcony'
// stamp='2002-09-10T23:41:07Z'/>
//
// The format [of the stamp attribute] MUST adhere to the dateTime format
// specified in XEP-0082 and MUST be expressed in UTC.
delay = [self elementForName:@"delay" xmlns:@"urn:xmpp:delay"];
if (delay)
{
NSString *stampValue = [delay attributeStringValueForName:@"stamp"];
// There are other considerations concerning XEP-0082.
// For example, it may optionally contain milliseconds.
// And it may possibly express UTC as "+00:00" instead of "Z".
//
// Thankfully there is already an implementation that takes into account all these possibilities.
NSDate* stamp = [XMPPDateTimeProfiles parseDateTime:stampValue];
//xuhai, I changed this bug. If the server time is newer than the current time, we should use the current time.
switch ([currentTime compare:stamp]){
case NSOrderedAscending:
NSLog(@"NSOrderedAscending");
stamp = currentTime;
break;
default:
break;
}
return stamp;
}
// From XEP-0091 (Legacy Delayed Delivery)
//
// <x xmlns='jabber:x:delay'
// from='capulet.com'
// stamp='20020910T23:08:25'>
delay = [self elementForName:@"x" xmlns:@"jabber:x:delay"];
if (delay)
{
NSDate *stamp;
NSString *stampValue = [delay attributeStringValueForName:@"stamp"];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
[dateFormatter setDateFormat:@"yyyyMMdd'T'HH:mm:ss"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
stamp = [dateFormatter dateFromString:stampValue];
switch ([currentTime compare:stamp]){
case NSOrderedAscending:
NSLog(@"NSOrderedAscending");
stamp = currentTime;
break;
default:
break;
}
return stamp;
}
return nil;
}
I have change the code in NSXMLElement+XEP_0203.m as followings: