@@ -1058,6 +1058,83 @@ describe('d', () => {
10581058 '12/20/2012, 07:00 AM'
10591059 )
10601060 } )
1061+
1062+ test ( 'parts formatting' , ( ) => {
1063+ const { d } = createComposer ( {
1064+ locale : 'en-US' ,
1065+ datetimeFormats : {
1066+ 'en-US' : {
1067+ short : {
1068+ year : 'numeric' ,
1069+ month : '2-digit' ,
1070+ day : '2-digit' ,
1071+ hour : '2-digit' ,
1072+ minute : '2-digit' ,
1073+ timeZone : 'America/New_York'
1074+ }
1075+ } ,
1076+ 'ja-JP' : {
1077+ long : {
1078+ year : 'numeric' ,
1079+ month : '2-digit' ,
1080+ day : '2-digit' ,
1081+ hour : '2-digit' ,
1082+ minute : '2-digit' ,
1083+ second : '2-digit' ,
1084+ timeZone : 'America/New_York'
1085+ } ,
1086+ short : {
1087+ year : 'numeric' ,
1088+ month : '2-digit' ,
1089+ day : '2-digit' ,
1090+ hour : '2-digit' ,
1091+ minute : '2-digit' ,
1092+ timeZone : 'Asia/Tokyo'
1093+ }
1094+ }
1095+ }
1096+ } )
1097+ const dt = new Date ( 2015 , 12 )
1098+ expect ( d ( dt , { key : 'short' , part : true , year : '2-digit' } ) ) . toEqual ( [
1099+ { type : 'month' , value : '12' } ,
1100+ { type : 'literal' , value : '/' } ,
1101+ { type : 'day' , value : '31' } ,
1102+ { type : 'literal' , value : '/' } ,
1103+ { type : 'year' , value : '15' } ,
1104+ { type : 'literal' , value : ', ' } ,
1105+ { type : 'hour' , value : '07' } ,
1106+ { type : 'literal' , value : ':' } ,
1107+ { type : 'minute' , value : '00' } ,
1108+ { type : 'literal' , value : ' ' } ,
1109+ { type : 'dayPeriod' , value : 'PM' }
1110+ ] )
1111+ expect ( d ( dt , { key : 'short' , locale : 'en-US' , part : true } ) ) . toEqual ( [
1112+ { type : 'month' , value : '12' } ,
1113+ { type : 'literal' , value : '/' } ,
1114+ { type : 'day' , value : '31' } ,
1115+ { type : 'literal' , value : '/' } ,
1116+ { type : 'year' , value : '2015' } ,
1117+ { type : 'literal' , value : ', ' } ,
1118+ { type : 'hour' , value : '07' } ,
1119+ { type : 'literal' , value : ':' } ,
1120+ { type : 'minute' , value : '00' } ,
1121+ { type : 'literal' , value : ' ' } ,
1122+ { type : 'dayPeriod' , value : 'PM' }
1123+ ] )
1124+ expect ( d ( dt , { key : 'long' , locale : 'ja-JP' , part : true } ) ) . toEqual ( [
1125+ { type : 'year' , value : '2015' } ,
1126+ { type : 'literal' , value : '/' } ,
1127+ { type : 'month' , value : '12' } ,
1128+ { type : 'literal' , value : '/' } ,
1129+ { type : 'day' , value : '31' } ,
1130+ { type : 'literal' , value : ' ' } ,
1131+ { type : 'hour' , value : '19' } ,
1132+ { type : 'literal' , value : ':' } ,
1133+ { type : 'minute' , value : '00' } ,
1134+ { type : 'literal' , value : ':' } ,
1135+ { type : 'second' , value : '00' }
1136+ ] )
1137+ } )
10611138} )
10621139
10631140describe ( 'n' , ( ) => {
0 commit comments