df4e24b66f70385e8cb0d73060fa4b5748b45b46.svn-base
2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#import "NSXMLElement+XEP_0203.h"
#import "XMPPDateTimeProfiles.h"
#import "NSXMLElement+XMPP.h"
#if ! __has_feature(objc_arc)
#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
#endif
@implementation NSXMLElement (XEP_0203)
- (BOOL)wasDelayed
{
NSXMLElement *delay;
delay = [self elementForName:@"delay" xmlns:@"urn:xmpp:delay"];
if (delay)
{
return YES;
}
delay = [self elementForName:@"x" xmlns:@"jabber:x:delay"];
if (delay)
{
return YES;
}
return NO;
}
- (NSDate *)delayedDeliveryDate
{
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.
return [XMPPDateTimeProfiles parseDateTime:stampValue];
}
// 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];
return stamp;
}
return nil;
}
@end