-
Notifications
You must be signed in to change notification settings - Fork 2
/
XMPPTimestamp.m
99 lines (87 loc) · 3.02 KB
/
XMPPTimestamp.m
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//
// XMPPTimestamp.m
// Jabber
//
// Created by David Chisnall on 20/08/2004.
// Copyright 2004 __MyCompanyName__. All rights reserved.
//
#import "XMPPTimestamp.h"
#import <EtoileFoundation/EtoileFoundation.h>
@implementation XMPPTimestamp
+ (id) timestampWithTime:(NSCalendarDate*)_time reason:(NSString*)_reason
{
return [[XMPPTimestamp alloc] initWithTime:_time reason:_reason];
}
- (id) initWithXMLParser: (ETXMLParser*)aParser
parent: (id <ETXMLParserDelegate>) aParent
key: (id) aKey
{
self = [super initWithXMLParser: aParser
key: aKey];
if (nil == self)
{
return nil;
}
value = self;
reason = [[NSMutableString alloc] init];
return self;
}
- (void)characters:(NSString *)chars
{
[reason appendString:chars];
}
/*
<x from='capulet.com'
stamp='20020910T23:08:25'
xmlns='jabber:x:delay'>
Offline Storage
</x>
*/
- (void)startElement:(NSString *)aName
attributes:(NSDictionary*)attributes
{
if([aName isEqualToString:@"x"]
&&
[[attributes objectForKey:@"xmlns"] isEqualToString:@"jabber:x:delay"])
{
depth++;
NSString * stamp = [attributes objectForKey:@"stamp"];
time = [NSCalendarDate dateWithYear:[[stamp substringWithRange:NSMakeRange(0,4)] intValue]
month:[[stamp substringWithRange:NSMakeRange(4,2)] intValue]
day:[[stamp substringWithRange:NSMakeRange(6,2)] intValue]
hour:[[stamp substringWithRange:NSMakeRange(9,2)] intValue]
minute:[[stamp substringWithRange:NSMakeRange(12,2)] intValue]
second:[[stamp substringWithRange:NSMakeRange(15,2)] intValue]
timeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
[time setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
}
else
{
[[[ETXMLNullHandler alloc] initWithXMLParser:parser
key:nil] startElement:aName
attributes:attributes];
}
}
- (id) initWithTime:(NSCalendarDate*)_time reason:(NSString*)_reason
{
reason = [_reason mutableCopy];
time = _time;
return [super init];
}
- (NSCalendarDate*) time
{
return time;
}
- (NSString*) reason
{
return reason;
}
- (NSString*) stamp
{
return [time descriptionWithCalendarFormat:@"%Y%m%dT%H:%M:%S"];
}
- (NSComparisonResult) compare:(XMPPTimestamp*)_other
{
return [time compare:[_other time]];
}
@end