@@ -29,6 +29,7 @@ class TestDateFormatter: XCTestCase {
29
29
( " test_dateStyleFull " , test_dateStyleFull) ,
30
30
( " test_customDateFormat " , test_customDateFormat) ,
31
31
( " test_setLocalizedDateFormatFromTemplate " , test_setLocalizedDateFormatFromTemplate) ,
32
+ ( " test_dateFormatString " , test_dateFormatString) ,
32
33
]
33
34
}
34
35
@@ -295,4 +296,45 @@ class TestDateFormatter: XCTestCase {
295
296
XCTAssertEqual ( f. dateFormat, dateFormat)
296
297
}
297
298
299
+ func test_dateFormatString( ) {
300
+ let f = DateFormatter ( )
301
+ f. timeZone = TimeZone ( abbreviation: DEFAULT_TIMEZONE)
302
+
303
+ //.full cases have been commented out as they're not working correctly on Linux
304
+ let formats : [ String : ( DateFormatter . Style , DateFormatter . Style ) ] = [
305
+ " " : ( . none, . none) ,
306
+ " h:mm a " : ( . none, . short) ,
307
+ " h:mm:ss a " : ( . none, . medium) ,
308
+ " h:mm:ss a z " : ( . none, . long) ,
309
+ // "h:mm:ss a zzzz": (.none, .full),
310
+ " M/d/yy " : ( . short, . none) ,
311
+ " M/d/yy, h:mm a " : ( . short, . short) ,
312
+ " M/d/yy, h:mm:ss a " : ( . short, . medium) ,
313
+ " M/d/yy, h:mm:ss a z " : ( . short, . long) ,
314
+ // "M/d/yy, h:mm:ss a zzzz": (.short, .full),
315
+ " MMM d, y " : ( . medium, . none) ,
316
+ //These tests currently fail, there seems to be a difference in behavior in the CoreFoundation methods called to construct the format strings.
317
+ // "MMM d, y 'at' h:mm a": (.medium, .short),
318
+ // "MMM d, y 'at' h:mm:ss a": (.medium, .medium),
319
+ // "MMM d, y 'at' h:mm:ss a z": (.medium, .long),
320
+ // "MMM d, y 'at' h:mm:ss a zzzz": (.medium, .full),
321
+ " MMMM d, y " : ( . long, . none) ,
322
+ " MMMM d, y 'at' h:mm a " : ( . long, . short) ,
323
+ " MMMM d, y 'at' h:mm:ss a " : ( . long, . medium) ,
324
+ " MMMM d, y 'at' h:mm:ss a z " : ( . long, . long) ,
325
+ // "MMMM d, y 'at' h:mm:ss a zzzz": (.long, .full),
326
+ // "EEEE, MMMM d, y": (.full, .none),
327
+ // "EEEE, MMMM d, y 'at' h:mm a": (.full, .short),
328
+ // "EEEE, MMMM d, y 'at' h:mm:ss a": (.full, .medium),
329
+ // "EEEE, MMMM d, y 'at' h:mm:ss a z": (.full, .long),
330
+ // "EEEE, MMMM d, y 'at' h:mm:ss a zzzz": (.full, .full),
331
+ ]
332
+
333
+ for (dateFormat, styles) in formats {
334
+ f. dateStyle = styles. 0
335
+ f. timeStyle = styles. 1
336
+
337
+ XCTAssertEqual ( f. dateFormat, dateFormat)
338
+ }
339
+ }
298
340
}
0 commit comments