-
Notifications
You must be signed in to change notification settings - Fork 27
/
ObjectiveResourceDateFormatterTest.m
64 lines (54 loc) · 2.93 KB
/
ObjectiveResourceDateFormatterTest.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
//
// ObjectiveResourceDateFormatterTest.m
// objective_support
//
// Created by James Burka on 2/25/09.
// Copyright 2009 Burkaprojects. All rights reserved.
//
#import "ObjectiveResourceDateFormatterTest.h"
#import "ObjectiveResourceDateFormatter.h"
@implementation ObjectiveResourceDateFormatterTest
-(void) testDefaultDate {
[ObjectiveResourceDateFormatter setDateFormatString:@"yyyy-MM-dd"];
[ObjectiveResourceDateFormatter setSerializeFormat:Date];
NSDate* aDate = [ObjectiveResourceDateFormatter parseDate:@"2009-02-25"];
STAssertEqualStrings([ObjectiveResourceDateFormatter formatDate:aDate],@"2009-02-25",@"Should match original");
}
-(void) testDefaultDateTime {
[ObjectiveResourceDateFormatter setDateTimeFormatString:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];
[ObjectiveResourceDateFormatter setSerializeFormat:DateTime];
NSDate* aDate = [ObjectiveResourceDateFormatter parseDateTime:@"2009-02-25T12:00:00Z"];
STAssertEqualStrings([ObjectiveResourceDateFormatter formatDate:aDate],@"2009-02-25T12:00:00Z",@"Should match original");
}
-(void) testTimeZoneSupport {
[ObjectiveResourceDateFormatter setDateTimeZoneFormatString:@"yyyy-MM-dd'T'HH:mm:ssz"];
[ObjectiveResourceDateFormatter setSerializeFormat:DateTime];
NSDate* aDate = [ObjectiveResourceDateFormatter parseDateTime:@"2009-02-25T23:45:00-5:00"];
STAssertEqualStrings([ObjectiveResourceDateFormatter formatDate:aDate],@"2009-02-26T04:45:00Z",@"Should match original in GMT");
}
-(void) testCustomDateFormat {
[ObjectiveResourceDateFormatter setSerializeFormat:Date];
[ObjectiveResourceDateFormatter setDateFormatString:@"MM-dd-yyyy"];
NSDate* aDate = [ObjectiveResourceDateFormatter parseDate:@"02-25-2009"];
STAssertEqualStrings([ObjectiveResourceDateFormatter formatDate:aDate],@"02-25-2009",@"Should match original");
}
-(void) testCustomDateTimeFormat {
[ObjectiveResourceDateFormatter setDateTimeFormatString:@"MM-dd-yyyy'T'HH:mm:ss'Z'"];
[ObjectiveResourceDateFormatter setSerializeFormat:DateTime];
NSDate* aDate = [ObjectiveResourceDateFormatter parseDateTime:@"02-25-2009T23:45:00Z"];
STAssertEqualStrings([ObjectiveResourceDateFormatter formatDate:aDate],@"02-25-2009T23:45:00Z",@"Should match original");
}
-(void) testCustomDateTimeWithTimeZoneFormat {
[ObjectiveResourceDateFormatter setSerializeFormat:DateTime];
[ObjectiveResourceDateFormatter setDateTimeZoneFormatString:@"MM-dd-yyyy'T'HH:mm:ssz"];
NSDate* aDate = [ObjectiveResourceDateFormatter parseDateTime:@"02-25-2009T23:45:00-5:00"];
STAssertEqualStrings([ObjectiveResourceDateFormatter formatDate:aDate],@"2009-02-26T04:45:00Z",@"Should match default format in GMT");
}
- (void)tearDown {
// reset defaults
[ObjectiveResourceDateFormatter setDateFormatString:@"yyyy-MM-dd"];
[ObjectiveResourceDateFormatter setDateTimeZoneFormatString:@"yyyy-MM-dd'T'HH:mm:ssz"];
[ObjectiveResourceDateFormatter setDateTimeFormatString:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];
[ObjectiveResourceDateFormatter setSerializeFormat:DateTime];
}
@end