@@ -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,36 @@ 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 omitted 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
+ " M/d/yy " : ( . short, . none) ,
310
+ " M/d/yy, h:mm a " : ( . short, . short) ,
311
+ " M/d/yy, h:mm:ss a " : ( . short, . medium) ,
312
+ " M/d/yy, h:mm:ss a z " : ( . short, . long) ,
313
+ " MMM d, y " : ( . medium, . none) ,
314
+ //These tests currently fail, there seems to be a difference in behavior in the CoreFoundation methods called to construct the format strings.
315
+ // "MMM d, y 'at' h:mm a": (.medium, .short),
316
+ // "MMM d, y 'at' h:mm:ss a": (.medium, .medium),
317
+ // "MMM d, y 'at' h:mm:ss a z": (.medium, .long),
318
+ " MMMM d, y " : ( . long, . none) ,
319
+ " MMMM d, y 'at' h:mm a " : ( . long, . short) ,
320
+ " MMMM d, y 'at' h:mm:ss a " : ( . long, . medium) ,
321
+ " MMMM d, y 'at' h:mm:ss a z " : ( . long, . long) ,
322
+ ]
323
+
324
+ for (dateFormat, styles) in formats {
325
+ f. dateStyle = styles. 0
326
+ f. timeStyle = styles. 1
327
+
328
+ XCTAssertEqual ( f. dateFormat, dateFormat)
329
+ }
330
+ }
298
331
}
0 commit comments