@@ -40,7 +40,7 @@ class ModelRocketTests: XCTestCase {
40
40
// Put setup code here. This method is called before the invocation of each test method in the class.
41
41
42
42
// Setup test model
43
- var jsonString = " { \" string \" : \" Test string \" , \" date \" : \" 2015-02-04T18:30:15.000Z \" , \" color \" : \" #00FF00 \" , \" bool \" : true, \" url \" : \" http://ovenbits.com \" , \" number \" : 3, \" double \" : 7.5, \" float \" : 4.75, \" int \" : -23, \" u_int \" : 25, \" string_enum \" : \" String1 \" , \" int_enum \" : 0} "
43
+ var jsonString = " { \" string \" : \" Test string \" , \" date \" : \" 2015-02-04T18:30:15.000Z \" , \" local_date \" : \" 2015-02-04T18:30:15.000-0600 \" , \" color \" : \" #00FF00 \" , \" bool \" : true, \" url \" : \" http://ovenbits.com \" , \" number \" : 3, \" double \" : 7.5, \" float \" : 4.75, \" int \" : -23, \" u_int \" : 25, \" string_enum \" : \" String1 \" , \" int_enum \" : 0} "
44
44
var jsonData = jsonString. dataUsingEncoding ( NSUTF8StringEncoding, allowLossyConversion: false )
45
45
var json = JSON ( data: jsonData!)
46
46
testModel = TestModel ( json: json)
@@ -76,7 +76,7 @@ class ModelRocketTests: XCTestCase {
76
76
testVeryComplexNestedModel = TestVeryComplexNestedModel ( json: json)
77
77
78
78
// Setup test subclass model
79
- jsonString = " { \" string \" : \" Test string \" , \" date \" : \" 2015-02-04T18:30:15.000Z \" , \" color \" : \" #00FF00 \" , \" bool \" : true, \" url \" : \" http://ovenbits.com \" , \" number \" : 3, \" double \" : 7.5, \" float \" : 4.75, \" int \" : -23, \" u_int \" : 25, \" string2 \" : \" Test string 2 \" } "
79
+ jsonString = " { \" string \" : \" Test string \" , \" date \" : \" 2015-02-04T18:30:15.000Z \" , \" local_date \" : \" 2015-02-04T18:30:15.000-0600 \" , \" color \" : \" #00FF00 \" , \" bool \" : true, \" url \" : \" http://ovenbits.com \" , \" number \" : 3, \" double \" : 7.5, \" float \" : 4.75, \" int \" : -23, \" u_int \" : 25, \" string2 \" : \" Test string 2 \" } "
80
80
jsonData = jsonString. dataUsingEncoding ( NSUTF8StringEncoding, allowLossyConversion: false )
81
81
json = JSON ( data: jsonData!)
82
82
testSubclassModel = TestSubclassModel ( json: json)
@@ -101,11 +101,13 @@ class ModelRocketTests: XCTestCase {
101
101
102
102
func testEquatableProperty( ) {
103
103
let dateFormatter = NSDateFormatter ( )
104
- dateFormatter. dateFormat = " yyyy-MM-dd'T'HH:mm:ss.SSS'Z' "
104
+ dateFormatter. dateFormat = " yyyy-MM-dd'T'HH:mm:ss.SSSZ "
105
105
let date = dateFormatter. dateFromString ( " 2015-02-04T18:30:15.000Z " )
106
+ let localDate = dateFormatter. dateFromString ( " 2015-02-04T18:30:15.000-0600 " )
106
107
107
108
XCTAssertTrue ( testModel. string == Property < String > ( key: " string " , defaultValue: " Test string " ) , " Properties not equal " )
108
109
XCTAssertTrue ( testModel. date == Property < NSDate > ( key: " date " , defaultValue: date) , " Properties not equal " )
110
+ XCTAssertTrue ( testModel. localDate == Property < NSDate > ( key: " local_date " , defaultValue: localDate) , " Properties not equal " )
109
111
XCTAssertTrue ( testModel. color == Property < UIColor > ( key: " color " , defaultValue: . greenColor( ) ) , " Properties not equal " )
110
112
XCTAssertTrue ( testModel. bool == Property < Bool > ( key: " bool " , defaultValue: true ) , " Properties not equal " )
111
113
XCTAssertTrue ( testModel. url == Property < NSURL > ( key: " url " , defaultValue: NSURL ( string: " http://ovenbits.com " ) ) , " Properties not equal " )
@@ -132,6 +134,8 @@ class ModelRocketTests: XCTestCase {
132
134
if let date = testModel. date. value {
133
135
134
136
let calendar = NSCalendar . currentCalendar ( )
137
+ calendar. timeZone = NSTimeZone ( forSecondsFromGMT: 0 )
138
+
135
139
let units : NSCalendarUnit = [ . Year, . Month, . Day, . Hour, . Minute, . Second, . Nanosecond]
136
140
let components = calendar. components ( units, fromDate: date)
137
141
@@ -147,6 +151,27 @@ class ModelRocketTests: XCTestCase {
147
151
}
148
152
}
149
153
154
+ func testLocalDate( ) {
155
+ if let date = testModel. localDate. value {
156
+
157
+ let calendar = NSCalendar . currentCalendar ( )
158
+ calendar. timeZone = NSTimeZone ( forSecondsFromGMT: 0 )
159
+
160
+ let units : NSCalendarUnit = [ . Year, . Month, . Day, . Hour, . Minute, . Second, . Nanosecond]
161
+ let components = calendar. components ( units, fromDate: date)
162
+
163
+ XCTAssertEqual ( components. year, 2015 , " Date: years not equal " )
164
+ XCTAssertEqual ( components. month, 2 , " Date: months not equal " )
165
+ XCTAssertEqual ( components. day, 5 , " Date: days not equal " )
166
+ XCTAssertEqual ( components. hour, 0 , " Date: hours not equal " )
167
+ XCTAssertEqual ( components. minute, 30 , " Date: minutes not equal " )
168
+ XCTAssertEqual ( components. second, 15 , " Date: seconds not equal " )
169
+ }
170
+ else {
171
+ XCTAssert ( false , " Test date should not be nil " )
172
+ }
173
+ }
174
+
150
175
func testColor( ) {
151
176
if let color = testModel. color. value {
152
177
XCTAssertEqual ( color, UIColor . greenColor ( ) , " Colors not equal " )
@@ -222,7 +247,8 @@ class ModelRocketTests: XCTestCase {
222
247
func testJSON( ) {
223
248
if let json = testModel. json ( ) . json {
224
249
XCTAssertEqual ( json [ " string " ] . stringValue, " Test string " , " Strings not equal " )
225
- XCTAssertEqual ( json [ " date " ] . stringValue, " 2015-02-04T18:30:15.000Z " , " Dates not equal " )
250
+ XCTAssertEqual ( json [ " date " ] . stringValue, " 2015-02-04T18:30:15.000+0000 " , " Dates not equal " )
251
+ XCTAssertEqual ( json [ " local_date " ] . stringValue, " 2015-02-05T00:30:15.000+0000 " , " Dates not equal " )
226
252
XCTAssertEqual ( json [ " color " ] . stringValue, " #00FF00 " , " Colors not equal " )
227
253
XCTAssertEqual ( json [ " bool " ] . boolValue, true , " Bools not equal " )
228
254
@@ -254,6 +280,8 @@ class ModelRocketTests: XCTestCase {
254
280
255
281
if let date = unarchived. date. value {
256
282
let calendar = NSCalendar . currentCalendar ( )
283
+ calendar. timeZone = NSTimeZone ( forSecondsFromGMT: 0 )
284
+
257
285
let units : NSCalendarUnit = [ . Year, . Month, . Day, . Hour, . Minute, . Second, . Nanosecond]
258
286
let components = calendar. components ( units, fromDate: date)
259
287
@@ -268,6 +296,24 @@ class ModelRocketTests: XCTestCase {
268
296
XCTAssert ( false , " Coding: date should not be nil " )
269
297
}
270
298
299
+ if let date = unarchived. localDate. value {
300
+ let calendar = NSCalendar . currentCalendar ( )
301
+ calendar. timeZone = NSTimeZone ( forSecondsFromGMT: 0 )
302
+
303
+ let units : NSCalendarUnit = [ . Year, . Month, . Day, . Hour, . Minute, . Second, . Nanosecond]
304
+ let components = calendar. components ( units, fromDate: date)
305
+
306
+ XCTAssertEqual ( components. year, 2015 , " Date: years not equal " )
307
+ XCTAssertEqual ( components. month, 2 , " Date: months not equal " )
308
+ XCTAssertEqual ( components. day, 5 , " Date: days not equal " )
309
+ XCTAssertEqual ( components. hour, 0 , " Date: hours not equal " )
310
+ XCTAssertEqual ( components. minute, 30 , " Date: minutes not equal " )
311
+ XCTAssertEqual ( components. second, 15 , " Date: seconds not equal " )
312
+ }
313
+ else {
314
+ XCTAssert ( false , " Coding: date should not be nil " )
315
+ }
316
+
271
317
if let color = unarchived. color. value { XCTAssertEqual ( color, UIColor . greenColor ( ) , " Colors not equal " ) }
272
318
else { XCTAssert ( false , " Coding: color should not be nil " ) }
273
319
@@ -475,7 +521,8 @@ class ModelRocketTests: XCTestCase {
475
521
func testSubclassJSON( ) {
476
522
if let json = testSubclassModel. json ( ) . json {
477
523
XCTAssertEqual ( json [ " string " ] . stringValue, " Test string " , " Strings not equal " )
478
- XCTAssertEqual ( json [ " date " ] . stringValue, " 2015-02-04T18:30:15.000Z " , " Dates not equal " )
524
+ XCTAssertEqual ( json [ " date " ] . stringValue, " 2015-02-04T18:30:15.000+0000 " , " Dates not equal " )
525
+ XCTAssertEqual ( json [ " local_date " ] . stringValue, " 2015-02-05T00:30:15.000+0000 " , " Dates not equal " )
479
526
XCTAssertEqual ( json [ " color " ] . stringValue, " #00FF00 " , " Colors not equal " )
480
527
XCTAssertEqual ( json [ " bool " ] . boolValue, true , " Bools not equal " )
481
528
@@ -566,6 +613,7 @@ class ModelRocketTests: XCTestCase {
566
613
class TestModel: Model {
567
614
let string = Property < String > ( key: " string " )
568
615
let date = Property < NSDate > ( key: " date " )
616
+ let localDate = Property < NSDate > ( key: " local_date " )
569
617
let color = Property < UIColor > ( key: " color " )
570
618
let bool = Property < Bool > ( key: " bool " )
571
619
let url = Property < NSURL > ( key: " url " )
0 commit comments