• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GENERATED SOURCE. DO NOT MODIFY. */
2 
3 // © 2016 and later: Unicode, Inc. and others.
4 // License & terms of use: http://www.unicode.org/copyright.html#License
5 /*
6  *******************************************************************************
7  * Copyright (C) 2001-2016, International Business Machines Corporation and    *
8  * others. All Rights Reserved.                                                *
9  *******************************************************************************
10  */
11 
12 /**
13  * Port From:   ICU4C v1.8.1 : format : DateIntervalFormatTest
14  * Source File: $ICU4CRoot/source/test/intltest/dtifmtts.cpp
15  **/
16 
17 package ohos.global.icu.dev.test.format;
18 
19 import java.text.FieldPosition;
20 import java.text.ParseException;
21 import java.text.ParsePosition;
22 import java.util.ArrayList;
23 import java.util.Date;
24 import java.util.List;
25 import java.util.ListIterator;
26 import java.util.Locale;
27 
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.junit.runners.JUnit4;
31 
32 import ohos.global.icu.dev.test.TestFmwk;
33 import ohos.global.icu.impl.Utility;
34 import ohos.global.icu.text.ConstrainedFieldPosition;
35 import ohos.global.icu.text.DateFormat;
36 import ohos.global.icu.text.DateIntervalFormat;
37 import ohos.global.icu.text.DateIntervalFormat.FormattedDateInterval;
38 import ohos.global.icu.text.DateIntervalInfo;
39 import ohos.global.icu.text.DateIntervalInfo.PatternInfo;
40 import ohos.global.icu.text.SimpleDateFormat;
41 import ohos.global.icu.util.Calendar;
42 import ohos.global.icu.util.DateInterval;
43 import ohos.global.icu.util.Output;
44 import ohos.global.icu.util.TimeZone;
45 import ohos.global.icu.util.ULocale;
46 
47 
48 
49 @RunWith(JUnit4.class)
50 public class DateIntervalFormatTest extends TestFmwk {
51 
52     /**
53      *
54      */
55     private static final ULocale SPANISH = new ULocale("es");
56     /**
57      *
58      */
59     private static final ULocale LA_SPANISH = new ULocale("es-419");
60 
61     /**
62      * Test format
63      */
64     @Test
TestFormat()65     public void TestFormat() {
66         // first item is date pattern
67         // followed by a group of locale/from_data/to_data/skeleton/interval_data
68         // Note that from_data/to_data are specified using era names from root, for the calendar specified by locale.
69         String[] DATA = {
70                 "GGGGG y MM dd HH:mm:ss", // pattern for from_data/to_data
71                 // test root
72                 "root", "CE 2007 11 10 10:10:10", "CE 2007 12 10 10:10:10", "yM", "2007-11 \\u2013 2007-12",
73 
74                 // test 'H' and 'h', using availableFormat in fallback
75                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 10 15:10:10", "Hms", "10:10:10 \\u2013 15:10:10",
76                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 10 15:10:10", "hms", "10:10:10 AM \\u2013 3:10:10 PM",
77 
78                 // test skeleton with both date and time
79                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "dMMMyhm", "Nov 10, 2007, 10:10 AM \\u2013 Nov 20, 2007, 10:10 AM",
80 
81                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 10 11:10:10", "dMMMyhm", "Nov 10, 2007, 10:10 \\u2013 11:10 AM",
82 
83                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 10 11:10:10", "hms", "10:10:10 AM \\u2013 11:10:10 AM",
84 
85                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "EEEEdMMMMy", "Wednesday, October 10, 2007 \\u2013 Friday, October 10, 2008",
86 
87                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "dMMMMy", "October 10, 2007 \\u2013 October 10, 2008",
88 
89                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "dMMMM", "October 10, 2007 \\u2013 October 10, 2008",
90 
91                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "MMMMy", "October 2007 \\u2013 October 2008",
92 
93                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "EEEEdMMMM", "Wednesday, October 10, 2007 \\u2013 Friday, October 10, 2008",
94 
95                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "EdMMMy", "Wed, Oct 10, 2007 \\u2013 Fri, Oct 10, 2008",
96 
97                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "dMMMy", "Oct 10, 2007 \\u2013 Oct 10, 2008",
98 
99                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "dMMM", "Oct 10, 2007 \\u2013 Oct 10, 2008",
100 
101                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "MMMy", "Oct 2007 \\u2013 Oct 2008",
102 
103                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "EdMMM", "Wed, Oct 10, 2007 \\u2013 Fri, Oct 10, 2008",
104 
105                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "EdMy", "Wed, 10/10/2007 \\u2013 Fri, 10/10/2008",
106 
107                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "dMy", "10/10/2007 \\u2013 10/10/2008",
108 
109                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "dM", "10/10/2007 \\u2013 10/10/2008",
110 
111                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "My", "10/2007 \\u2013 10/2008",
112 
113                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "EdM", "Wed, 10/10/2007 \\u2013 Fri, 10/10/2008",
114 
115                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "d", "10/10/2007 \\u2013 10/10/2008",
116 
117                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "Ed", "10 Wed \\u2013 10 Fri",
118 
119                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "y", "2007 \\u2013 2008",
120 
121                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "M", "10/2007 \\u2013 10/2008",
122 
123                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "MMM", "Oct 2007 \\u2013 Oct 2008",
124 
125                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "MMMM", "October 2007 \\u2013 October 2008",
126 
127                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "hm", "10/10/2007, 10:10 AM \\u2013 10/10/2008, 10:10 AM",
128 
129                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "hmv", "10/10/2007, 10:10 AM PT \\u2013 10/10/2008, 10:10 AM PT",
130 
131                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "hmz", "10/10/2007, 10:10 AM PDT \\u2013 10/10/2008, 10:10 AM PDT",
132 
133                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "h", "10/10/2007, 10 AM \\u2013 10/10/2008, 10 AM",
134 
135                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "hv", "10/10/2007, 10 AM PT \\u2013 10/10/2008, 10 AM PT",
136 
137                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "hz", "10/10/2007, 10 AM PDT \\u2013 10/10/2008, 10 AM PDT",
138 
139                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "EEddMMyyyy", "Wed, 10/10/2007 \\u2013 Fri, 10/10/2008",
140 
141                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "EddMMy", "Wed, 10/10/2007 \\u2013 Fri, 10/10/2008",
142 
143                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "hhmm", "10/10/2007, 10:10 AM \\u2013 10/10/2008, 10:10 AM",
144 
145                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "hhmmzz", "10/10/2007, 10:10 AM PDT \\u2013 10/10/2008, 10:10 AM PDT",
146 
147                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "hms", "10/10/2007, 10:10:10 AM \\u2013 10/10/2008, 10:10:10 AM",
148 
149                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "dMMMMMy", "O 10, 2007 \\u2013 O 10, 2008",
150 
151                 "en", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "EEEEEdM", "W, 10/10/2007 \\u2013 F, 10/10/2008",
152 
153                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "EEEEdMMMMy", "Wednesday, October 10 \\u2013 Saturday, November 10, 2007",
154 
155                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "dMMMMy", "October 10 \\u2013 November 10, 2007",
156 
157                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "dMMMM", "October 10 \\u2013 November 10",
158 
159                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "MMMMy", "October \\u2013 November 2007",
160 
161                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "EEEEdMMMM", "Wednesday, October 10 \\u2013 Saturday, November 10",
162 
163                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "EdMMMy", "Wed, Oct 10 \\u2013 Sat, Nov 10, 2007",
164 
165                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "dMMMy", "Oct 10 \\u2013 Nov 10, 2007",
166 
167                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "dMMM", "Oct 10 \\u2013 Nov 10",
168 
169                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "MMMy", "Oct \\u2013 Nov 2007",
170 
171                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "EdMMM", "Wed, Oct 10 \\u2013 Sat, Nov 10",
172 
173                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "EdMy", "Wed, 10/10/2007 \\u2013 Sat, 11/10/2007",
174 
175                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "dMy", "10/10/2007 \\u2013 11/10/2007",
176 
177                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "dM", "10/10 \\u2013 11/10",
178 
179                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "My", "10/2007 \\u2013 11/2007",
180 
181                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "EdM", "Wed, 10/10 \\u2013 Sat, 11/10",
182 
183                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "d", "10/10 \\u2013 11/10",
184 
185                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "Ed", "10 Wed \\u2013 10 Sat",
186 
187                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "y", "2007",
188 
189                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "M", "10 \\u2013 11",
190 
191                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "MMM", "Oct \\u2013 Nov",
192 
193                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "MMMM", "October \\u2013 November",
194 
195                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "hm", "10/10/2007, 10:10 AM \\u2013 11/10/2007, 10:10 AM",
196 
197                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "hmv", "10/10/2007, 10:10 AM PT \\u2013 11/10/2007, 10:10 AM PT",
198 
199                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "hmz", "10/10/2007, 10:10 AM PDT \\u2013 11/10/2007, 10:10 AM PST",
200 
201                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "h", "10/10/2007, 10 AM \\u2013 11/10/2007, 10 AM",
202 
203                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "hv", "10/10/2007, 10 AM PT \\u2013 11/10/2007, 10 AM PT",
204 
205                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "hz", "10/10/2007, 10 AM PDT \\u2013 11/10/2007, 10 AM PST",
206 
207                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "EEddMMyyyy", "Wed, 10/10/2007 \\u2013 Sat, 11/10/2007",
208 
209                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "EddMMy", "Wed, 10/10/2007 \\u2013 Sat, 11/10/2007",
210 
211                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "hhmm", "10/10/2007, 10:10 AM \\u2013 11/10/2007, 10:10 AM",
212 
213                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "hhmmzz", "10/10/2007, 10:10 AM PDT \\u2013 11/10/2007, 10:10 AM PST",
214 
215                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "hms", "10/10/2007, 10:10:10 AM \\u2013 11/10/2007, 10:10:10 AM",
216 
217                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "dMMMMMy", "O 10 \\u2013 N 10, 2007",
218 
219                 "en", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "EEEEEdM", "W, 10/10 \\u2013 S, 11/10",
220 
221                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "EEEEdMMMMy", "Saturday, November 10 \\u2013 Tuesday, November 20, 2007",
222 
223                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "dMMMMy", "November 10 \\u2013 20, 2007",
224 
225                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "dMMMM", "November 10 \\u2013 20",
226 
227                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "MMMMy", "November 2007",
228 
229                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "EEEEdMMMM", "Saturday, November 10 \\u2013 Tuesday, November 20",
230 
231                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "EdMMMy", "Sat, Nov 10 \\u2013 Tue, Nov 20, 2007",
232 
233 
234                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "dMMM", "Nov 10 \\u2013 20",
235 
236                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "MMMy", "Nov 2007",
237 
238                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "EdMMM", "Sat, Nov 10 \\u2013 Tue, Nov 20",
239 
240                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "EdMy", "Sat, 11/10/2007 \\u2013 Tue, 11/20/2007",
241 
242                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "dMy", "11/10/2007 \\u2013 11/20/2007",
243 
244                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "dM", "11/10 \\u2013 11/20",
245 
246                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "My", "11/2007",
247                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "EdM", "Sat, 11/10 \\u2013 Tue, 11/20",
248 
249                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "d", "10 \\u2013 20",
250                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "Ed", "10 Sat \\u2013 20 Tue",
251 
252                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "M", "11",
253 
254                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "MMM", "Nov",
255 
256                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "hm", "11/10/2007, 10:10 AM \\u2013 11/20/2007, 10:10 AM",
257 
258                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "hmv", "11/10/2007, 10:10 AM PT \\u2013 11/20/2007, 10:10 AM PT",
259 
260                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "hmz", "11/10/2007, 10:10 AM PST \\u2013 11/20/2007, 10:10 AM PST",
261 
262                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "hz", "11/10/2007, 10 AM PST \\u2013 11/20/2007, 10 AM PST",
263 
264                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "EEddMMyyyy", "Sat, 11/10/2007 \\u2013 Tue, 11/20/2007",
265 
266                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "EddMMy", "Sat, 11/10/2007 \\u2013 Tue, 11/20/2007",
267 
268                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "hhmm", "11/10/2007, 10:10 AM \\u2013 11/20/2007, 10:10 AM",
269 
270                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "hms", "11/10/2007, 10:10:10 AM \\u2013 11/20/2007, 10:10:10 AM",
271 
272                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "dMMMMMy", "N 10 \\u2013 20, 2007",
273 
274                 "en", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "EEEEEdM", "S, 11/10 \\u2013 T, 11/20",
275 
276                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "EEEEdMMMMy", "Wednesday, January 10, 2007",
277 
278                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "dMMMMy", "January 10, 2007",
279 
280                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "dMMMM", "January 10",
281 
282                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "MMMMy", "January 2007",
283 
284                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "EEEEdMMMM", "Wednesday, January 10",
285 
286 
287                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "dMMMy", "Jan 10, 2007",
288 
289                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "dMMM", "Jan 10",
290 
291                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "MMMy", "Jan 2007",
292 
293                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "EdMMM", "Wed, Jan 10",
294 
295                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "EdMy", "Wed, 1/10/2007",
296 
297                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "dMy", "1/10/2007",
298 
299                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "dM", "1/10",
300 
301 
302                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "EdM", "Wed, 1/10",
303 
304                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "d", "10",
305 
306                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "Ed", "10 Wed",
307 
308                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "y", "2007",
309 
310 
311                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "MMM", "Jan",
312 
313                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "MMMM", "January",
314 
315                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "hm", "10:00 AM \\u2013 2:10 PM",
316 
317 
318                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "hmz", "10:00 AM \\u2013 2:10 PM PST",
319 
320                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "h", "10 AM \\u2013 2 PM",
321 
322                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "hv", "10 AM \\u2013 2 PM PT",
323 
324                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "hz", "10 AM \\u2013 2 PM PST",
325 
326                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "EEddMMyyyy", "Wed, 01/10/2007",
327 
328 
329                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "hhmm", "10:00 AM \\u2013 2:10 PM",
330 
331                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "hhmmzz", "10:00 AM \\u2013 2:10 PM PST",
332 
333 
334                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "dMMMMMy", "J 10, 2007",
335 
336                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "EEEEEdM", "W, 1/10",
337 
338                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "EEEEdMMMMy", "Wednesday, January 10, 2007",
339 
340                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "dMMMMy", "January 10, 2007",
341 
342 
343                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "MMMMy", "January 2007",
344 
345 
346                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "EdMMMy", "Wed, Jan 10, 2007",
347 
348                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "dMMMy", "Jan 10, 2007",
349 
350                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "dMMM", "Jan 10",
351 
352 
353                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "EdMMM", "Wed, Jan 10",
354 
355                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "EdMy", "Wed, 1/10/2007",
356 
357 
358                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "dM", "1/10",
359 
360 
361                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "EdM", "Wed, 1/10",
362 
363 
364 
365                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "y", "2007",
366 
367 
368                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "MMM", "Jan",
369 
370 
371                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "hm", "10:00 \\u2013 10:20 AM",
372 
373                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "hmv", "10:00 \\u2013 10:20 AM PT",
374 
375 
376                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "h", "10 AM",
377 
378 
379                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "hz", "10 AM PST",
380 
381 
382                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "EddMMy", "Wed, 01/10/2007",
383 
384                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "hhmm", "10:00 \\u2013 10:20 AM",
385 
386                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "hhmmzz", "10:00 \\u2013 10:20 AM PST",
387 
388                 "en", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "hms", "10:00:10 AM \\u2013 10:20:10 AM",
389 
390                 "en", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "dMMMM", "January 10",
391 
392                 "en", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "EEEEdMMMM", "Wednesday, January 10",
393 
394                 "en", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "EdMMMy", "Wed, Jan 10, 2007",
395 
396                 "en", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "dMMM", "Jan 10",
397 
398                 "en", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "EdMMM", "Wed, Jan 10",
399                 "en", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "dM", "1/10",
400 
401                 "en", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "My", "1/2007",
402 
403                 "en", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "EdM", "Wed, 1/10",
404                 "en", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "d", "10",
405 
406                 "en", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "Ed", "10 Wed",
407 
408                 "en", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "y", "2007",
409 
410                 "en", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "M", "1",
411 
412                 "en", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "MMM", "Jan",
413 
414                 "en", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "MMMM", "January",
415 
416                 "en", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "hm", "10:10 AM",
417 
418                 "en", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "hmv", "10:10 AM PT",
419 
420                 "en", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "hmz", "10:10 AM PST",
421 
422                 "en", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "h", "10 AM",
423 
424 
425                 "en", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "hz", "10 AM PST",
426 
427                 "en", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "hhmmzz", "10:10 AM PST",
428 
429                 "en", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "hms", "10:10:10 AM \u2013 10:10:20 AM",
430 
431                 "en", "CE 2007 01 01 22:00:00", "CE 2007 01 01 23:00:00", "yMMMMdHm", "January 1, 2007, 22:00 \u2013 23:00",
432 
433                 "zh", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "EEEEdMMMMy", "2007\\u5e7410\\u670810\\u65e5\\u661f\\u671f\\u4e09\\u81f32008\\u5e7410\\u670810\\u65e5\\u661f\\u671f\\u4e94",
434 
435                 "zh", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "hm", "2007/10/10 \\u4e0a\\u534810:10 \\u2013 2008/10/10 \\u4e0a\\u534810:10",
436 
437                 "zh", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "dMMMMy", "2007\\u5e7410\\u670810\\u65e5\\u81f311\\u670810\\u65e5",
438 
439                 "zh", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "dMMMM", "10\\u670810\\u65e5\\u81f311\\u670810\\u65e5",
440 
441                 "zh", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "MMMMy", "2007\\u5e7410\\u6708\\u81f311\\u6708",
442 
443                 "zh", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "EEEEdMMMM", "10\\u670810\\u65e5\\u661f\\u671f\\u4e09\\u81f311\\u670810\\u65e5\\u661f\\u671f\\u516d",
444 
445                 "zh", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "hmv", "2007/10/10 \\u6D1B\\u6749\\u77F6\\u65F6\\u95F4 \\u4E0A\\u534810:10 \\u2013 2007/11/10 \\u6D1B\\u6749\\u77F6\\u65F6\\u95F4 \\u4E0A\\u534810:10",
446 
447                 "zh", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "EEEEdMMMMy", "2007\\u5e7411\\u670810\\u65e5\\u661f\\u671f\\u516d\\u81f320\\u65e5\\u661f\\u671f\\u4e8c",
448 
449                 "zh", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "dMMMMy", "2007\\u5e7411\\u670810\\u65e5\\u81f320\\u65e5",
450 
451                 "zh", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "dMMMM", "11\\u670810\\u65e5\\u81f320\\u65e5",
452 
453                 "zh", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "MMMMy", "2007\\u5E7411\\u6708", // (fixed expected result per ticket 6872<-6626)
454 
455                 "zh", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "EEEEdMMMM", "11\\u670810\\u65e5\\u661f\\u671f\\u516d\\u81f320\\u65e5\\u661f\\u671f\\u4e8c",
456 
457                 "zh", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "EdMMM", "11\\u670810\\u65e5\\u5468\\u516d\\u81f320\\u65e5\\u5468\\u4e8c",
458 
459                 "zh", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "EdMy", "2007/11/10\\u5468\\u516d\\u81f32007/11/20\\u5468\\u4e8c",
460 
461                 "zh", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "dMy", "2007/11/10 \\u2013 2007/11/20",
462 
463                 "zh", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "dM", "11/10 \\u2013 11/20",
464 
465                 "zh", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "My", "2007\u5E7411\u6708",
466                 "zh", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "EdM", "11/10\\u5468\\u516d\\u81f311/20\\u5468\\u4e8c",
467 
468                 "zh", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "d", "10\\u201320\\u65e5",
469 
470                 "zh", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "y", "2007\\u5E74", // (fixed expected result per ticket:6626:)
471 
472                 "zh", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "M", "11\\u6708",
473 
474                 "zh", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "MMM", "11\\u6708", // (fixed expected result per ticket 6872<-6626 and others)
475 
476                 "zh", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "MMMM", "\\u5341\\u4E00\\u6708", // (fixed expected result per ticket 6872<-6626 and others)
477 
478                 "zh", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "hmz", "2007/11/10 GMT-8 \\u4e0a\\u534810:10 \\u2013 2007/11/20 GMT-8 \\u4e0a\\u534810:10",
479 
480                 "zh", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "h", "2007/11/10 \\u4e0a\\u534810\\u65f6 \\u2013 2007/11/20 \\u4e0a\\u534810\\u65f6",
481 
482                 "zh", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "EEEEdMMMMy", "2007\\u5e741\\u670810\\u65e5\\u661f\\u671f\\u4e09", // (fixed expected result per ticket 6872<-6626)
483 
484                 "zh", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "hm", "\\u4e0a\\u534810:00\\u81f3\\u4e0b\\u53482:10",
485 
486                 "zh", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "hmv", "\\u6D1B\\u6749\\u77F6\\u65F6\\u95F4\\u4E0A\\u534810:00\\u81F3\\u4E0B\\u53482:10",
487 
488                 "zh", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "hmz", "GMT-8\\u4e0a\\u534810:00\\u81f3\\u4e0b\\u53482:10",
489 
490                 "zh", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "h", "\\u4e0a\\u534810\\u65F6\\u81f3\\u4e0b\\u53482\\u65f6",
491 
492                 "zh", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "hv", "\\u6D1B\\u6749\\u77F6\\u65F6\\u95F4\\u4E0A\\u534810\\u65F6\\u81F3\\u4E0B\\u53482\\u65F6",
493 
494                 "zh", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "hz", "GMT-8\\u4e0a\\u534810\\u65F6\\u81f3\\u4e0b\\u53482\\u65f6",
495 
496                 "zh", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "dMMMM", "1\\u670810\\u65e5", // (fixed expected result per ticket 6872<-6626)
497 
498                 "zh", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "hm", "\\u4e0a\\u534810:00\\u81f310:20",
499 
500                 "zh", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "hmv", "\\u6D1B\\u6749\\u77F6\\u65F6\\u95F4\\u4E0A\\u534810:00\\u81F310:20",
501 
502                 "zh", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "h", "\\u4e0a\\u534810\\u65f6",
503 
504                 "zh", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "hz", "GMT-8\\u4e0a\\u534810\\u65f6",
505 
506                 "zh", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "EEEEdMMMMy", "2007\\u5e741\\u670810\\u65e5\\u661f\\u671f\\u4e09", // (fixed expected result per ticket 6872<-6626)
507 
508                 "zh", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "hm", "\\u4e0a\\u534810:10",
509 
510                 "zh", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "h", "\\u4e0a\\u534810\\u65f6",
511 
512                 "de", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "EEEEdMMMy", "Mittwoch, 10. Okt. 2007 \\u2013 Freitag, 10. Okt. 2008",
513 
514                 "de", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "dMMMy", "10. Okt. 2007 \\u2013 10. Okt. 2008",
515 
516                 "de", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "dMMM", "10. Okt. 2007 \\u2013 10. Okt. 2008",
517 
518                 "de", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "MMMy", "Okt. 2007 \\u2013 Okt. 2008",
519 
520                 "de", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "EEEdMMM", "Mi., 10. Okt. 2007 \\u2013 Fr., 10. Okt. 2008",
521 
522                 "de", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "EdMy", "Mi., 10.10.2007 \\u2013 Fr., 10.10.2008",
523 
524                 "de", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "dMy", "10.10.2007 \\u2013 10.10.2008",
525 
526                 "de", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "dM", "10.10.2007 \\u2013 10.10.2008",
527 
528                 "de", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "My", "10.2007 \\u2013 10.2008",
529 
530                 "de", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "EdM", "Mi., 10.10.2007 \\u2013 Fr., 10.10.2008",
531 
532                 "de", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "d", "10.10.2007 \\u2013 10.10.2008",
533 
534                 "de", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "y", "2007\\u20132008",
535 
536                 "de", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "M", "10.2007 \\u2013 10.2008",
537 
538                 "de", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "MMM", "Okt. 2007 \\u2013 Okt. 2008",
539 
540                 "de", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "hm", "10.10.2007, 10:10 AM \\u2013 10.10.2008, 10:10 AM",
541 
542                 "de", "CE 2007 10 10 10:10:10", "CE 2008 10 10 10:10:10", "jm", "10.10.2007, 10:10 \\u2013 10.10.2008, 10:10",
543 
544                 "de", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "EEEEdMMMy", "Mittwoch, 10. Okt. \\u2013 Samstag, 10. Nov. 2007",
545 
546                 "de", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "dMMMy", "10. Okt. \\u2013 10. Nov. 2007",
547 
548                 "de", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "dMMM", "10. Okt. \\u2013 10. Nov.",
549 
550                 "de", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "MMMy", "Okt.\\u2013Nov. 2007",
551 
552                 "de", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "EEEEdMMM", "Mittwoch, 10. Okt. \\u2013 Samstag, 10. Nov.",
553 
554                 "de", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "EdMy", "Mi., 10.10. \\u2013 Sa., 10.11.2007",
555 
556                 "de", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "dM", "10.10. \\u2013 10.11.",
557 
558                 "de", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "My", "10.2007 \\u2013 11.2007",
559 
560                 "de", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "EdM", "Mi., 10.10. \\u2013 Sa., 10.11.",
561 
562                 "de", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "d", "10.10. \\u2013 10.11.",
563 
564 
565                 "de", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "M", "10.\\u201311.",
566 
567                 "de", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "MMM", "Okt.\\u2013Nov.",
568 
569                 "de", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "hmv", "10.10.2007, 10:10 AM Los Angeles Zeit \\u2013 10.11.2007, 10:10 AM Los Angeles Zeit",
570 
571                 "de", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "jmv", "10.10.2007, 10:10 Los Angeles Zeit \\u2013 10.11.2007, 10:10 Los Angeles Zeit",
572 
573                 "de", "CE 2007 10 10 10:10:10", "CE 2007 11 10 10:10:10", "hms", "10.10.2007, 10:10:10 AM \\u2013 10.11.2007, 10:10:10 AM",
574 
575                 "de", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "EEEEdMMMy", "Samstag, 10. \\u2013 Dienstag, 20. Nov. 2007",
576 
577                 "de", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "dMMMy", "10.\\u201320. Nov. 2007",
578 
579                 "de", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "dMMM", "10.\\u201320. Nov.",
580 
581                 "de", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "MMMy", "Nov. 2007",
582 
583                 "de", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "EEEEdMMM", "Samstag, 10. \\u2013 Dienstag, 20. Nov.",
584 
585                 "de", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "EdMy", "Sa., 10. \\u2013 Di., 20.11.2007",
586 
587                 "de", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "dMy", "10.\\u201320.11.2007",
588 
589                 "de", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "dM", "10.\\u201320.11.",
590 
591                 "de", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "My", "11.2007",
592 
593                 "de", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "EdM", "Sa., 10. \\u2013 Di., 20.11.",
594 
595                 "de", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "d", "10.\\u201320.",
596 
597                 "de", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "y", "2007",
598 
599                 "de", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "M", "11",
600 
601                 "de", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "hmv", "10.11.2007, 10:10 AM Los Angeles Zeit \\u2013 20.11.2007, 10:10 AM Los Angeles Zeit",
602 
603                 "de", "CE 2007 11 10 10:10:10", "CE 2007 11 20 10:10:10", "jmv", "10.11.2007, 10:10 Los Angeles Zeit \\u2013 20.11.2007, 10:10 Los Angeles Zeit",
604 
605                 "de", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "EEEEdMMMy", "Mittwoch, 10. Jan. 2007",
606 
607                 "de", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "dMMMy", "10. Jan. 2007",
608 
609                 "de", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "dMMM", "10. Jan.",
610 
611                 "de", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "MMMy", "Jan. 2007",
612 
613                 "de", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "EEEEdMMM", "Mittwoch, 10. Jan.",
614 
615                 "de", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "hmz", "10:00 AM \\u2013 2:10 PM GMT-8",
616 
617                 "de", "CE 2007 01 10 10:00:10", "CE 2007 01 10 14:10:10", "h", "10 Uhr AM \\u2013 2 Uhr PM",
618 
619                 "de", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "EEEEdMMM", "Mittwoch, 10. Jan.",
620 
621                 "de", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "hm", "10:00\\u201310:20 AM",
622 
623                 "de", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "hmv", "10:00\\u201310:20 AM Los Angeles Zeit",
624 
625                 "de", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "hmz", "10:00\\u201310:20 AM GMT-8",
626 
627                 "de", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "h", "10 Uhr AM",
628 
629                 "de", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "hv", "10 Uhr AM Los Angeles Zeit",
630 
631                 "de", "CE 2007 01 10 10:00:10", "CE 2007 01 10 10:20:10", "hz", "10 Uhr AM GMT-8",
632 
633                 "de", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "EEEEdMMMy", "Mittwoch, 10. Jan. 2007",
634 
635                 "de", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "hm", "10:10 AM",
636 
637                 "de", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "jm", "10:10",
638 
639                 "de", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "hmv", "10:10 AM Los Angeles Zeit",
640 
641                 "de", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "jmv", "10:10 Los Angeles Zeit",
642 
643                 "de", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "hmz", "10:10 AM GMT-8",
644 
645                 "de", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "jmz", "10:10 GMT-8",
646 
647                 "de", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "h", "10 Uhr AM",
648 
649                 "de", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "hv", "10 Uhr AM Los Angeles Zeit",
650 
651                 "de", "CE 2007 01 10 10:10:10", "CE 2007 01 10 10:10:20", "hz", "10 Uhr AM GMT-8",
652 
653                 // Thai (default calendar buddhist)
654 
655                 "th@calendar=buddhist", "BE 2550 10 10 10:10:10", "BE 2551 10 10 10:10:10", "EEEEdMMMy", "\\u0E27\\u0E31\\u0E19\\u0E1E\\u0E38\\u0E18\\u0E17\\u0E35\\u0E48 10 \\u0E15.\\u0E04. 2550 \\u2013 \\u0E27\\u0E31\\u0E19\\u0E28\\u0E38\\u0E01\\u0E23\\u0E4C\\u0E17\\u0E35\\u0E48 10 \\u0E15.\\u0E04. 2551",
656 
657 
658                 "th@calendar=buddhist", "BE 2550 10 10 10:10:10", "BE 2551 10 10 10:10:10", "dMMM", "10 \\u0E15.\\u0E04. 2550 \\u2013 10 \\u0E15.\\u0E04. 2551",
659 
660                 "th@calendar=buddhist", "BE 2550 10 10 10:10:10", "BE 2551 10 10 10:10:10", "MMMy", "\\u0E15.\\u0E04. 2550 \\u2013 \\u0E15.\\u0E04. 2551",
661 
662 
663                 "th@calendar=buddhist", "BE 2550 10 10 10:10:10", "BE 2551 10 10 10:10:10", "EdMy", "\\u0E1E. 10/10/2550 \\u2013 \\u0E28. 10/10/2551",
664 
665                 "th@calendar=buddhist", "BE 2550 10 10 10:10:10", "BE 2551 10 10 10:10:10", "dMy", "10/10/2550 \\u2013 10/10/2551",
666 
667 
668                 "th@calendar=buddhist", "BE 2550 10 10 10:10:10", "BE 2551 10 10 10:10:10", "My", "10/2550 \\u2013 10/2551",
669 
670                 "th@calendar=buddhist", "BE 2550 10 10 10:10:10", "BE 2551 10 10 10:10:10", "EdM", "\\u0E1E. 10/10/2550 \\u2013 \\u0E28. 10/10/2551",
671 
672 
673                 "th@calendar=buddhist", "BE 2550 10 10 10:10:10", "BE 2551 10 10 10:10:10", "y", "2550\\u20132551",
674 
675                 "th@calendar=buddhist", "BE 2550 10 10 10:10:10", "BE 2551 10 10 10:10:10", "M", "10/2550 \\u2013 10/2551",
676 
677 
678                 "th@calendar=buddhist", "BE 2550 10 10 10:10:10", "BE 2550 11 10 10:10:10", "EEEEdMMMy", "\\u0E27\\u0E31\\u0E19\\u0E1E\\u0E38\\u0E18\\u0E17\\u0E35\\u0E48 10 \\u0E15.\\u0E04. \\u2013 \\u0E27\\u0E31\\u0E19\\u0E40\\u0E2A\\u0E32\\u0E23\\u0E4C\\u0E17\\u0E35\\u0E48 10 \\u0E1E.\\u0E22. 2550",
679 
680 
681                 "th@calendar=buddhist", "BE 2550 10 10 10:10:10", "BE 2550 11 10 10:10:10", "dMMM", "10 \\u0E15.\\u0E04. \\u2013 10 \\u0E1E.\\u0E22.",
682 
683                 "th@calendar=buddhist", "BE 2550 10 10 10:10:10", "BE 2550 11 10 10:10:10", "MMMy", "\\u0E15.\\u0E04.\\u2013\\u0E1E.\\u0E22. 2550",
684 
685                 "th@calendar=buddhist", "BE 2550 10 10 10:10:10", "BE 2550 11 10 10:10:10", "dM", "10/10 \\u2013 10/11",
686 
687                 "th@calendar=buddhist", "BE 2550 10 10 10:10:10", "BE 2550 11 10 10:10:10", "My", "10/2550 \\u2013 11/2550",
688 
689 
690                 "th@calendar=buddhist", "BE 2550 10 10 10:10:10", "BE 2550 11 10 10:10:10", "d", "10/10 \\u2013 10/11",
691 
692                 "th@calendar=buddhist", "BE 2550 10 10 10:10:10", "BE 2550 11 10 10:10:10", "y", "\u0E1E.\u0E28. 2550",
693 
694 
695                 "th@calendar=buddhist", "BE 2550 10 10 10:10:10", "BE 2550 11 10 10:10:10", "MMM", "\u0E15.\u0E04.\u2013\u0E1E.\u0E22.",
696 
697                 // Tests for Japanese calendar with eras, including new era in 2019 (Heisei 31 through April 30, then new era)
698 
699                 "en-u-ca-japanese", "H 31 03 15 09:00:00", "H 31 04 15 09:00:00", "GyMMMd", "Mar 15 \u2013 Apr 15, 31 Heisei",
700 
701                 "en-u-ca-japanese", "H 31 03 15 09:00:00", "H 31 04 15 09:00:00", "GGGGGyMd", "3/15/31 \u2013 4/15/31 H",
702 
703                 "en-u-ca-japanese", "S 64 01 05 09:00:00", "H 1 01 15 09:00:00",  "GyMMMd", "Jan 5, 64 Sh\u014Dwa \u2013 Jan 15, 1 Heisei",
704 
705                 "en-u-ca-japanese", "S 64 01 05 09:00:00", "H 1 01 15 09:00:00",  "GGGGGyMd", "1/5/64 S \u2013 1/15/1 H",
706 
707                 "en-u-ca-japanese", "H 31 04 15 09:00:00", DateFormat.JP_ERA_2019_NARROW+" 1 05 15 09:00:00",  "GyMMMd", "Apr 15, 31 Heisei \u2013 May 15, 1 "+DateFormat.JP_ERA_2019_ROOT,
708 
709                 "en-u-ca-japanese", "H 31 04 15 09:00:00", DateFormat.JP_ERA_2019_NARROW+" 1 05 15 09:00:00",  "GGGGGyMd", "4/15/31 H \u2013 5/15/1 "+DateFormat.JP_ERA_2019_NARROW,
710 
711 
712                 "ja-u-ca-japanese", "H 31 03 15 09:00:00", "H 31 04 15 09:00:00", "GyMMMd", "\u5E73\u621031\u5E743\u670815\u65E5\uFF5E4\u670815\u65E5",
713 
714                 "ja-u-ca-japanese", "H 31 03 15 09:00:00", "H 31 04 15 09:00:00", "GGGGGyMd", "H31/03/15\uFF5E31/04/15",
715 
716                 "ja-u-ca-japanese", "S 64 01 05 09:00:00", "H 1 01 15 09:00:00",  "GyMMMd", "\u662D\u548C64\u5E741\u67085\u65E5\uFF5E\u5E73\u6210\u5143\u5E741\u670815\u65E5",
717 
718                 "ja-u-ca-japanese", "S 64 01 05 09:00:00", "H 1 01 15 09:00:00",  "GGGGGyMd", "S64/01/05\uFF5EH1/01/15",
719 
720                 "ja-u-ca-japanese", "H 31 04 15 09:00:00", DateFormat.JP_ERA_2019_NARROW+" 1 05 15 09:00:00", "GGGGGyMd", "H31/04/15\uFF5E"+DateFormat.JP_ERA_2019_NARROW+"1/05/15",
721 
722         };
723         expect(DATA, DATA.length);
724     }
725 
726 
expect(String[] data, int data_length)727     private void expect(String[] data, int data_length) {
728         int i = 0;
729         String pattern = data[i++];
730 
731         while (i<data_length) {
732             String locName = data[i++];
733             String datestr = data[i++];
734             String datestr_2 = data[i++];
735 
736             ULocale loc = new ULocale(locName);
737             Calendar defCal = Calendar.getInstance(loc);
738             String calType = defCal.getType();
739 
740             ULocale refLoc = ULocale.ROOT.setKeywordValue("calendar", calType);
741             SimpleDateFormat ref = new SimpleDateFormat(pattern, refLoc);
742             // 'f'
743             Date date, date_2;
744             try {
745                 date = ref.parse(datestr);
746                 date_2 = ref.parse(datestr_2);
747             } catch ( ParseException e ) {
748                 errln("parse exception" + e);
749                 i += 2; // skip the rest of the strings for this item
750                 continue;
751             }
752             DateInterval dtitv = new DateInterval(date.getTime(),
753                     date_2.getTime());
754             String oneSkeleton = data[i++];
755             DateIntervalFormat dtitvfmt = DateIntervalFormat.getInstance(
756                     oneSkeleton, loc);
757             String expected = data[i++];
758             String formatted = dtitvfmt.format(dtitv);
759             if ( !formatted.equals(Utility.unescape(expected)) )  {
760                 errln("\"" + locName + "\\" + oneSkeleton + "\\" + datestr + "\\" + datestr_2 + "\"\t expected: " + expected +"\tgot: " + formatted + "\n");
761             }
762         }
763     }
764 
765 
766     /*
767      * Test format using user defined DateIntervalInfo
768      */
769     @Test
TestFormatUserDII()770     public void TestFormatUserDII() {
771         // first item is date pattern
772         // followed by a group of locale/from_data/to_data/interval_data
773         String[] DATA = {
774                 "yyyy MM dd HH:mm:ss",
775                 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "Oct 10, 2007 --- Oct 10, 2008",
776 
777                 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "2007 Oct 10 - Nov 2007",
778 
779                 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "Nov 10, 2007 --- Nov 20, 2007",
780 
781                 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "Jan 10, 2007",
782 
783                 "en", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "Jan 10, 2007",
784 
785                 "en", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "Jan 10, 2007",
786 
787                 "zh", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "2007\\u5e7410\\u670810\\u65e5 --- 2008\\u5e7410\\u670810\\u65e5",
788 
789 
790                 "zh", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "2007\\u5e7411\\u670810\\u65e5 --- 2007\\u5e7411\\u670820\\u65e5",
791 
792                 "zh", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "2007\\u5e741\\u670810\\u65e5", // (fixed expected result per ticket 6872<-6626)
793 
794                 "zh", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "2007\\u5e741\\u670810\\u65e5", // (fixed expected result per ticket 6872<-6626)
795 
796                 "zh", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "2007\\u5e741\\u670810\\u65e5", // (fixed expected result per ticket 6872<-6626)
797 
798                 "de", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "10. Okt. 2007 --- 10. Okt. 2008",
799 
800                 "de", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "2007 Okt. 10 - Nov. 2007",
801 
802                 "de", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "10. Nov. 2007 --- 20. Nov. 2007",
803 
804                 "de", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "10. Jan. 2007",
805 
806                 "de", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "10. Jan. 2007",
807 
808                 "de", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "10. Jan. 2007",
809 
810                 "es", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "10 oct. 2007 --- 10 oct. 2008",
811 
812                 "es", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "2007 oct. 10 - nov. 2007",
813 
814                 "es", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "10 nov. 2007 --- 20 nov. 2007",
815 
816                 "es", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "10 ene. 2007",
817 
818                 "es", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "10 ene. 2007",
819 
820                 "es", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "10 ene. 2007",
821         };
822         expectUserDII(DATA, DATA.length);
823     }
824 
825 
expectUserDII(String[] data, int data_length)826     private void expectUserDII(String[] data, int data_length) {
827         int i = 1;
828         while (i<data_length) {
829             String locName = data[i++];
830             ULocale loc = new ULocale(locName);
831             SimpleDateFormat ref = new SimpleDateFormat(data[0], loc);
832             // 'f'
833             String datestr = data[i++];
834             String datestr_2 = data[i++];
835             Date date, date_2;
836             try {
837                 date = ref.parse(datestr);
838                 date_2 = ref.parse(datestr_2);
839             } catch ( ParseException e ) {
840                 errln("parse exception" + e);
841                 continue;
842             }
843             DateInterval dtitv = new DateInterval(date.getTime(),
844                     date_2.getTime());
845 
846             DateIntervalInfo dtitvinf = new DateIntervalInfo();
847             dtitvinf.setFallbackIntervalPattern("{0} --- {1}");
848             dtitvinf.setIntervalPattern("yMMMd", Calendar.MONTH, "yyyy MMM d - MMM y");
849             dtitvinf.setIntervalPattern("yMMMd", Calendar.HOUR_OF_DAY, "yyyy MMM d HH:mm - HH:mm");
850             DateIntervalFormat dtitvfmt = DateIntervalFormat.getInstance(
851                     DateFormat.YEAR_ABBR_MONTH_DAY,
852                     loc, dtitvinf);
853             String expected = data[i++];
854             String formatted = dtitvfmt.format(dtitv);
855             if ( !formatted.equals(Utility.unescape(expected)) )  {
856                 errln("userDII: \"" + locName + "\\" + datestr + "\\" + datestr_2 + "\"\t expected: " + expected +"\tgot: " + formatted + "\n");
857             }
858         }
859     }
860 
861 
862 
863     /*
864      * Test format using user defined DateIntervalInfo
865      */
866     @Test
TestFormatCLDR()867     public void TestFormatCLDR() {
868         // first item is date pattern
869         // followed by a group of locale/from_data/to_data/interval_data
870         String[] DATA = {
871                 "yyyy MM dd HH:mm:ss",
872                 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "all diff",
873 
874                 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "2007 diff Oct 10 - Nov 2007",
875 
876                 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "2007 Nov 10 ~ 20",
877 
878                 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "Jan 10, 2007",
879 
880                 "en", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "Jan 10, 2007",
881 
882                 "en", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "Jan 10, 2007",
883 
884                 "zh", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "all diff",
885 
886                 "zh", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "2007 diff 10\\u6708 10 - 11\\u6708 2007",
887 
888                 "zh", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "2007 11\\u6708 10 ~ 20",
889 
890                 "zh", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "2007\u5E741\\u670810\u65E5", // (fixed expected result per ticket 6872<-6626)
891 
892                 "zh", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "2007\u5E741\\u670810\u65E5", // (fixed expected result per ticket 6872<-6626)
893 
894                 "zh", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "2007\u5E741\\u670810\u65E5", // (fixed expected result per ticket 6872<-6626)
895         };
896         expectUserCLDR(DATA, DATA.length);
897     }
898 
899 
expectUserCLDR(String[] data, int data_length)900     private void expectUserCLDR(String[] data, int data_length) {
901         int i = 1;
902         while (i<data_length) {
903             String locName = data[i++];
904             ULocale loc = new ULocale(locName);
905             SimpleDateFormat ref = new SimpleDateFormat(data[0], loc);
906             // 'f'
907             String datestr = data[i++];
908             String datestr_2 = data[i++];
909             Date date, date_2;
910             try {
911                 date = ref.parse(datestr);
912                 date_2 = ref.parse(datestr_2);
913             } catch ( ParseException e ) {
914                 errln("parse exception" + e);
915                 continue;
916             }
917             DateInterval dtitv = new DateInterval(date.getTime(),
918                     date_2.getTime());
919 
920             DateIntervalFormat dtitvfmt = DateIntervalFormat.getInstance("yyyyMMMdd", loc);
921             //DateIntervalFormat dtitvfmt = DateIntervalFormat.getInstance("yMd");
922             //SimpleDateFormat dtfmt = new SimpleDateFormat("yyyy 'year' MMM 'month' dd 'day'", loc);
923             //dtitvfmt.setDateFormat(dtfmt);
924             DateIntervalInfo dtitvinf = new DateIntervalInfo();
925             dtitvinf.setFallbackIntervalPattern("{0} --- {1}");
926             dtitvinf.setIntervalPattern("yMMMd", Calendar.YEAR, "'all diff'");
927             dtitvinf.setIntervalPattern("yMMMd", Calendar.MONTH, "yyyy 'diff' MMM d - MMM y");
928             dtitvinf.setIntervalPattern("yMMMd", Calendar.DATE, "yyyy MMM d ~ d");
929             dtitvinf.setIntervalPattern("yMMMd", Calendar.HOUR_OF_DAY, "yyyy MMMd HH:mm ~ HH:mm");
930             dtitvfmt.setDateIntervalInfo(dtitvinf);
931             FieldPosition pos = new FieldPosition(0);
932             StringBuffer str = new StringBuffer("");
933             DateFormat dtfmt = dtitvfmt.getDateFormat();
934             Calendar fromCalendar = (Calendar) dtfmt.getCalendar().clone();
935             Calendar toCalendar = (Calendar) dtfmt.getCalendar().clone();
936             fromCalendar.setTimeInMillis(dtitv.getFromDate());
937             toCalendar.setTimeInMillis(dtitv.getToDate());
938             dtitvfmt.format(fromCalendar, toCalendar, str, pos);
939 
940             String expected = data[i++];
941             String formatted = dtitvfmt.format(dtitv).toString();
942             if ( !formatted.equals(Utility.unescape(expected)) )  {
943                 errln("CLDR: \"" + locName + "\\" + datestr + "\\" + datestr_2 + "\"\t expected: " + expected +"\tgot: " + formatted + "\n");
944             }
945         }
946     }
947 
948 
949     /**
950      * Stress test
951      */
952     @Test
TestStress()953     public void TestStress() {
954         if (TestFmwk.getExhaustiveness() <= 5) {
955             logln("INFO: Skipping test");
956             return;
957         }
958 
959         // test data.
960         // The 1st is the format pattern,
961         // Next are pairs in which the 1st in the pair is the earlier date
962         // and the 2nd in the pair is the later date
963         String[] DATA = {
964                 "yyyy MM dd HH:mm:ss",
965                 "2007 10 10 10:10:10", "2008 10 10 10:10:10",
966                 "2007 10 10 10:10:10", "2007 11 10 10:10:10",
967                 "2007 11 10 10:10:10", "2007 11 20 10:10:10",
968                 "2007 01 10 10:00:10", "2007 01 10 14:10:10",
969                 "2007 01 10 10:00:10", "2007 01 10 10:20:10",
970                 "2007 01 10 10:10:10", "2007 01 10 10:10:20",
971         };
972 
973 
974         String[][] testLocale = {
975                 {"en", "", ""},
976                 {"zh", "", ""},
977                 {"de", "", ""},
978                 {"ar", "", ""},
979                 {"en", "GB",  ""},
980                 {"fr", "", ""},
981                 {"it", "", ""},
982                 {"nl", "", ""},
983                 {"zh", "TW",  ""},
984                 {"ja", "", ""},
985                 {"pt", "BR", ""},
986                 {"ru", "", ""},
987                 {"tr", "", ""},
988                 {"es", "", ""},
989                 {"ko", "", ""},
990                 //{"th", "", ""},
991                 {"sv", "", ""},
992                 {"pl", "", ""},
993                 {"fi", "", ""},
994                 {"da", "", ""},
995                 {"pt", "PT", ""},
996                 {"ro", "", ""},
997                 {"hu", "", ""},
998                 {"he", "", ""},
999                 {"in", "", ""},
1000                 {"cs", "", ""},
1001                 {"el", "", ""},
1002                 {"no", "", ""},
1003                 {"vi", "", ""},
1004                 {"bg", "", ""},
1005                 {"hr", "", ""},
1006                 {"lt", "", ""},
1007                 {"sk", "", ""},
1008                 {"sl", "", ""},
1009                 {"sr", "", ""},
1010                 {"ca", "", ""},
1011                 {"lv", "", ""},
1012                 {"uk", "", ""},
1013                 {"hi", "", ""},
1014         };
1015 
1016         int localeIndex;
1017         for ( localeIndex = 0; localeIndex < testLocale.length; ++localeIndex) {
1018             stress(DATA, DATA.length, new Locale(testLocale[localeIndex][0],
1019                     testLocale[localeIndex][1], testLocale[localeIndex][2]),
1020                     testLocale[localeIndex][0]+testLocale[localeIndex][1]);
1021         }
1022     }
1023 
stress(String[] data, int data_length, Locale loc, String locName)1024     private void stress(String[] data, int data_length, Locale loc, String locName) {
1025         String[] skeleton = {
1026                 "EEEEdMMMMy",
1027                 "dMMMMy",
1028                 "dMMMM",
1029                 "MMMMy",
1030                 "EEEEdMMMM",
1031                 "EEEdMMMy",
1032                 "dMMMy",
1033                 "dMMM",
1034                 "MMMy",
1035                 "EEEdMMM",
1036                 "EEEdMy",
1037                 "dMy",
1038                 "dM",
1039                 "My",
1040                 "EEEdM",
1041                 "d",
1042                 "EEEd",
1043                 "y",
1044                 "M",
1045                 "MMM",
1046                 "MMMM",
1047                 "hm",
1048                 "hmv",
1049                 "hmz",
1050                 "h",
1051                 "hv",
1052                 "hz",
1053                 "EEddMMyyyy", // following could be normalized
1054                 "EddMMy",
1055                 "hhmm",
1056                 "hhmmzz",
1057                 "hms",  // following could not be normalized
1058                 "dMMMMMy",
1059                 "EEEEEdM",
1060         };
1061 
1062         int i = 0;
1063 
1064         SimpleDateFormat ref = new SimpleDateFormat(data[i++], loc);
1065 
1066         while (i<data_length) {
1067             // 'f'
1068             String datestr = data[i++];
1069             String datestr_2 = data[i++];
1070             Date date;
1071             Date date_2;
1072             try {
1073                 date = ref.parse(datestr);
1074                 date_2 = ref.parse(datestr_2);
1075             } catch ( ParseException e ) {
1076                 errln("parse exception" + e);
1077                 continue;
1078             }
1079             DateInterval dtitv = new DateInterval(date.getTime(), date_2.getTime());
1080 
1081             for ( int skeletonIndex = 0;
1082                     skeletonIndex < skeleton.length;
1083                     ++skeletonIndex ) {
1084                 String oneSkeleton = skeleton[skeletonIndex];
1085                 // need special handle of "Thai" since the default calendar
1086                 // of "Thai" is "Budd", not "Gregorian".
1087                 DateIntervalFormat dtitvfmt = DateIntervalFormat.getInstance(oneSkeleton, loc);
1088                 /*
1089                 if ( locName.equals("th") ) {
1090                     // reset calendar to be Gregorian
1091                     GregorianCalendar gregCal = new GregorianCalendar(loc);
1092                     DateFormat dformat = dtitvfmt.getDateFormat();
1093                     DateFormat newOne = (DateFormat)dformat.clone();
1094                     newOne.setCalendar(gregCal);
1095                     dtitvfmt.setDateFormat(newOne);
1096                 }
1097                  */
1098                 dtitvfmt.format(dtitv);
1099             }
1100 
1101 
1102             // test interval format by algorithm
1103             for ( int style = DateFormat.FULL; style  < 4; ++style ) {
1104                 SimpleDateFormat dtfmt = (SimpleDateFormat) DateFormat.getDateInstance(style, loc);
1105                 FieldPosition pos = new FieldPosition(0);
1106                 StringBuffer str = new StringBuffer("");
1107                 Calendar fromCalendar = (Calendar) dtfmt.getCalendar().clone();
1108                 Calendar toCalendar = (Calendar) dtfmt.getCalendar().clone();
1109                 fromCalendar.setTimeInMillis(dtitv.getFromDate());
1110                 toCalendar.setTimeInMillis(dtitv.getToDate());
1111                 dtfmt.intervalFormatByAlgorithm(fromCalendar, toCalendar, str, pos);
1112             }
1113         }
1114     }
1115 
1116     /*
1117      * Ticket#6396 DateIntervalInfo of ICU4J 4.0d3 throw NullPointerException
1118      */
1119     @Test
TestT6396()1120     public void TestT6396() {
1121         DateIntervalInfo dii = new DateIntervalInfo(new ULocale("th_TH"));
1122         try {
1123             // ticket#6396 reported toString() throws NullPointerException
1124             String diiStr = dii.toString();
1125             logln("new DateIntervalInfo(new ULocale(\"th_TH\")).toString() - " + diiStr);
1126 
1127             // equals also had the similar problem
1128             DateIntervalInfo dii1 = (DateIntervalInfo)dii.clone();
1129             if (!dii.equals(dii1)) {
1130                 errln("FAIL: Cloned DateIntervalInfo is not equal to the source");
1131             }
1132         } catch (Exception e) {
1133             errln("FAIL: Exception - " + e.getClass().getName());
1134         }
1135     }
1136 
1137     @Test
TestConstructor()1138     public void TestConstructor() {
1139         DateIntervalInfo diiJapan = new DateIntervalInfo(ULocale.JAPAN);
1140         DateIntervalInfo diiJapanJ = new DateIntervalInfo(Locale.JAPAN);
1141 
1142         assertEquals("DateIntervalInfo constructors", diiJapan, diiJapanJ);
1143     }
1144 
1145     /* Tests the method
1146      *      public boolean equals(Object a)
1147      */
1148     @Test
TestDateIntervalInfoEquals()1149     public void TestDateIntervalInfoEquals(){
1150         // Tests when "if ( a instanceof PatternInfo )" is false
1151         DateIntervalInfo diia = new DateIntervalInfo();
1152         if(diia.equals("dummy")){
1153             errln("DateIntervalInfo.equals(Object a) was suppose to return " +
1154                     "false for a String object.");
1155         }
1156         if(diia.equals(0)){
1157             errln("DateIntervalInfo.equals(Object a) was suppose to return " +
1158                     "false for an Integer object.");
1159         }
1160         if(diia.equals(0.0)){
1161             errln("DateIntervalInfo.equals(Object a) was suppose to return " +
1162                     "false for an Integer object.");
1163         }
1164         if(diia.equals(new Object())){
1165             errln("DateIntervalInfo.equals(Object a) was suppose to return " +
1166                     "false for an Integer object.");
1167         }
1168     }
1169 
1170     /* Tests the method
1171      *      public Object cloneAsThawed()
1172      */
1173     @Test
TestCloseAsThawed()1174     public void TestCloseAsThawed(){
1175         DateIntervalInfo dii = new DateIntervalInfo();
1176         try{
1177             dii.cloneAsThawed();
1178         } catch(Exception e){
1179             errln("DateIntervalInfo.closeAsThawed() was not suppose to return " +
1180                     "an exception.");
1181         }
1182     }
1183 
1184     /* Tests the method
1185      *      public boolean isFrozen()
1186      */
1187     @Test
TestIsFrozen()1188     public void TestIsFrozen(){
1189         DateIntervalInfo dii = new DateIntervalInfo();
1190         if(dii.isFrozen() != false){
1191             errln("DateIntervalInfo.isFrozen() is suppose to return false.");
1192         }
1193         dii.freeze();
1194 
1195         if(dii.isFrozen() != true){
1196             errln("DateIntervalInfo.isFrozen() is suppose to return true.");
1197         }
1198     }
1199 
1200     /* Tests the method
1201      *      public boolean clone()
1202      */
1203     @Test
TestClone()1204     public void TestClone(){
1205         DateIntervalInfo dii = new DateIntervalInfo(new ULocale("en_US"));
1206         DateIntervalInfo dii_clone = (DateIntervalInfo) dii.clone();
1207         dii_clone.freeze();
1208 
1209         // Tests when "if ( frozen )" is true
1210         if(!dii.equals(dii_clone)){
1211             errln("DateIntervalInfo.clone() is suppose to return true for " +
1212                     "an original DateIntervalInfo object and a clone of the " +
1213                     "original DateIntervalInfo object.");
1214         }
1215     }
1216 
1217     /* Tests the method
1218      *      public void setFallbackIntervalPattern(String fallbackPattern)
1219      */
1220     @Test
TestSetFallbackIntervalPattern()1221     public void TestSetFallbackIntervalPattern(){
1222         DateIntervalInfo dii = new DateIntervalInfo(new ULocale("en_US"));
1223         // Tests when "if ( frozen )" is true
1224         try{
1225             dii.freeze();
1226             dii.setFallbackIntervalPattern("");
1227             errln("DateIntervalInfo.setFallbackIntervalPattern(String fallbackPattern) " +
1228                     "was suppose to return an exception for a frozen object.");
1229         } catch (Exception e){}
1230 
1231         // Tests when "if ( firstPatternIndex == -1 || secondPatternIndex == -1 )" is true
1232         dii = dii.cloneAsThawed();
1233         try{
1234             dii.setFallbackIntervalPattern("");
1235             errln("DateIntervalInfo.setFallbackIntervalPattern(String fallbackPattern) " +
1236                     "was suppose to return an exception for a string object of ''.");
1237         } catch(Exception e){}
1238 
1239         try{
1240             dii.setFallbackIntervalPattern("0");
1241             errln("DateIntervalInfo.setFallbackIntervalPattern(String fallbackPattern) " +
1242                     "was suppose to return an exception for a string object of 0.");
1243         } catch(Exception e){}
1244 
1245         // Tests when "if ( firstPatternIndex > secondPatternIndex )" is true
1246         dii.setFallbackIntervalPattern("{1}{0}");
1247         if(dii.getDefaultOrder() != true)
1248             errln("DateIntervalInfo.setFallbackIntervalPattern(String fallbackPattern) " +
1249                     "was suppose to change the variable 'fFirstDateInPtnIsLaterDate' " +
1250                     "to true.");
1251     }
1252 
1253     /* Tests the method
1254      *      public PatternInfo getIntervalPattern(String skeleton, int field)
1255      */
1256     @Test
TestGetIntervalPattern()1257     public void TestGetIntervalPattern(){
1258         // Tests when "if ( field > MINIMUM_SUPPORTED_CALENDAR_FIELD )" is true
1259         // MINIMUM_SUPPORTED_CALENDAR_FIELD = Calendar.MILLISECOND;
1260         DateIntervalInfo dii = new DateIntervalInfo();
1261         try{
1262             dii.getIntervalPattern("", Calendar.MILLISECOND+1);
1263             errln("DateIntervalInfo.getIntervalPattern(String,int) was suppose " +
1264                     "to return an exception for the 'int field' parameter " +
1265                     "when it exceeds MINIMUM_SUPPORTED_CALENDAR_FIELD.");
1266         } catch(Exception e){}
1267     }
1268 
1269     /* Tests the method
1270      *      public void setIntervalPattern(String skeleton, int lrgDiffCalUnit, String intervalPattern)
1271      */
1272     @Test
TestSetIntervalPattern()1273     public void TestSetIntervalPattern(){
1274         DateIntervalInfo dii = new DateIntervalInfo();
1275         // Tests when "if ( frozen )" is true
1276         try{
1277             dii.freeze();
1278             dii.setIntervalPattern("", 0, "");
1279             errln("DateIntervalInfo.setIntervalPattern(String,int,String) " +
1280                     "was suppose to return an exception when the " +
1281                     "DateIntervalInfo object is frozen.");
1282         } catch(Exception e){}
1283 
1284         // Tests when "if ( lrgDiffCalUnit > MINIMUM_SUPPORTED_CALENDAR_FIELD )" is true
1285         // MINIMUM_SUPPORTED_CALENDAR_FIELD = Calendar.MILLISECOND;
1286         try{
1287             dii = dii.cloneAsThawed();
1288             dii.setIntervalPattern("", Calendar.MILLISECOND+1, "");
1289             errln("DateIntervalInfo.setIntervalPattern(String,int,String) " +
1290                     "was suppose to return an exception when the " +
1291                     "variable 'lrgDiffCalUnit' is greater than " +
1292                     "MINIMUM_SUPPORTED_CALENDAR_FIELD.");
1293         } catch(Exception e){}
1294     }
1295 
1296     @Test
TestSetIntervalPatternNoSideEffect()1297     public void TestSetIntervalPatternNoSideEffect() {
1298         PatternInfo patternInfo = new DateIntervalInfo(ULocale.ENGLISH).getIntervalPattern("yMd", Calendar.DATE);
1299         String expectedPattern = patternInfo.getFirstPart() + patternInfo.getSecondPart();
1300         new DateIntervalInfo(ULocale.ENGLISH).setIntervalPattern(
1301                 "yMd", Calendar.DATE, "M/d/y \u2013 d");
1302         patternInfo = new DateIntervalInfo(ULocale.ENGLISH).getIntervalPattern("yMd", Calendar.DATE);
1303         String actualPattern = patternInfo.getFirstPart() + patternInfo.getSecondPart();
1304         assertEquals(
1305                 "setIntervalPattern should not have side effects",
1306                 expectedPattern,
1307                 actualPattern);
1308     }
1309 
1310     @Test
TestGetSetTimeZone()1311     public void TestGetSetTimeZone(){
1312         DateIntervalFormat dtitvfmt = DateIntervalFormat.getInstance("MMMdHHmm", Locale.ENGLISH);
1313         long date1 = 1299090600000L; // 2011-Mar-02 1030 in US/Pacific, 2011-Mar-03 0330 in Asia/Tokyo
1314         long date2 = 1299115800000L; // 2011-Mar-02 1730 in US/Pacific, 2011-Mar-03 1030 in Asia/Tokyo
1315         DateInterval dtitv = new DateInterval(date1, date2);
1316         TimeZone tzCalif = TimeZone.getFrozenTimeZone("US/Pacific");
1317         TimeZone tzTokyo = TimeZone.getFrozenTimeZone("Asia/Tokyo");
1318         String fmtCalif = "Mar 2, 10:30 \u2013 17:30"; // ICU4C result is "Mar 2, 10:30 \u2013 17:30" (does not duplicate day)
1319         String fmtTokyo = "Mar 3, 03:30 \u2013 10:30"; // ICU4C result is "Mar 3, 03:30 \u2013 10:30" (does not duplicate day)
1320 
1321         StringBuffer buf = new StringBuffer();
1322         FieldPosition pos = new FieldPosition(0);
1323         dtitvfmt.setTimeZone(tzCalif);
1324         dtitvfmt.format(dtitv, buf, pos);
1325         if (!buf.toString().equals(fmtCalif)) {
1326             errln("DateIntervalFormat for tzCalif, expect \"" + fmtCalif + "\", get \"" + buf + "\"");
1327         }
1328 
1329         buf.setLength(0);
1330         pos.setBeginIndex(0);
1331         dtitvfmt.setTimeZone(tzTokyo);
1332         dtitvfmt.format(dtitv, buf, pos);
1333         if (!buf.toString().equals(fmtTokyo)) {
1334             errln("DateIntervalFormat for tzTokyo, expect \"" + fmtTokyo + "\", get \"" + buf + "\"");
1335         }
1336 
1337         if (!dtitvfmt.getTimeZone().equals(tzTokyo)) {
1338             errln("DateIntervalFormat.getTimeZone() returns mismatch");
1339         }
1340     }
1341 
1342 
1343     /* Tests the method
1344      *      public int hashCode()
1345      */
1346     @Test
TestHashCode()1347     public void TestHashCode(){
1348         // Tests when
1349         //      "int hash = fIntervalPatternFirstPart != null ? fIntervalPatternFirstPart.hashCode() : 0;"
1350         // is false
1351         PatternInfo dp = new PatternInfo(null, null, false);
1352         if(dp.hashCode() != 0){
1353             errln("PatternInfo.hashCode() was suppose to return 0 for a null " +
1354                     "paramter in the constructor.");
1355         }
1356     }
1357 
1358     /* Tests the method
1359      *      public boolean equals(Object a)
1360      * in PatternInfo
1361      */
1362     @Test
TestPattternInfoEquals()1363     public void TestPattternInfoEquals(){
1364         // Tests when "if ( a instanceof PatternInfo )" is false
1365         PatternInfo pi = new PatternInfo("","", false);
1366         if(pi.equals(new Object())){
1367             errln("PatternInfo.equals(Object) is suppose to return false " +
1368                     "when it is not an instance of PatternInfo.");
1369         }
1370         if(pi.equals("")){
1371             errln("PatternInfo.equals(Object) is suppose to return false " +
1372                     "when it is not an instance of PatternInfo.");
1373         }
1374         if(pi.equals(0)){
1375             errln("PatternInfo.equals(Object) is suppose to return false " +
1376                     "when it is not an instance of PatternInfo.");
1377         }
1378         if(pi.equals(0.0)){
1379             errln("PatternInfo.equals(Object) is suppose to return false " +
1380                     "when it is not an instance of PatternInfo.");
1381         }
1382     }
1383 
1384     @Test
TestDateIntervalCoverage()1385     public void TestDateIntervalCoverage() {
1386         DateInterval di = new DateInterval(0, 1);
1387 
1388         if (di.equals("Test")) {
1389             errln("Comparison test should fail.");
1390         }
1391 
1392         if (di.toString() == null) {
1393             errln("toString should not return null.");
1394         }
1395 
1396         if (di.hashCode() != 1) {
1397             errln("hasCode() should return 1.");
1398         }
1399     }
1400 
1401     @Test
testGetInstance_String_DateIntervalInfo()1402     public void testGetInstance_String_DateIntervalInfo() {
1403         DateIntervalInfo dateIntervalInfo = new DateIntervalInfo(new ULocale("ca"));
1404         DateIntervalFormat dateIntervalFormat = DateIntervalFormat.getInstance(
1405                 DateFormat.YEAR_MONTH, Locale.ENGLISH, dateIntervalInfo);
1406         Calendar from = Calendar.getInstance();
1407         from.set(2000, Calendar.JANUARY, 1, 12, 0);
1408         Calendar to = Calendar.getInstance();
1409         to.set(2001, Calendar.FEBRUARY, 1, 12, 0);
1410         DateInterval interval = new DateInterval(from.getTimeInMillis(), to.getTimeInMillis());
1411         dateIntervalFormat.setTimeZone(from.getTimeZone());
1412         // Month names are default (English), format is Catalan
1413         assertEquals("Wrong date interval",
1414                 "January de 2000 – February de 2001", dateIntervalFormat.format(interval));
1415     }
1416 
1417     @Test
testGetInstance_String_Locale_DateIntervalInfo()1418     public void testGetInstance_String_Locale_DateIntervalInfo() {
1419         DateIntervalInfo dateIntervalInfo = new DateIntervalInfo(new ULocale("ca"));
1420         DateIntervalFormat dateIntervalFormat = DateIntervalFormat.getInstance(
1421                 DateFormat.YEAR_MONTH, Locale.GERMAN, dateIntervalInfo);
1422         Calendar from = Calendar.getInstance();
1423         from.set(2000, Calendar.JANUARY, 1, 12, 0);
1424         Calendar to = Calendar.getInstance();
1425         to.set(2001, Calendar.FEBRUARY, 1, 12, 0);
1426         DateInterval interval = new DateInterval(from.getTimeInMillis(), to.getTimeInMillis());
1427         dateIntervalFormat.setTimeZone(from.getTimeZone());
1428         // Month names are German, format is Catalan
1429         assertEquals("Wrong date interval",
1430                 "Januar de 2000 – Februar de 2001", dateIntervalFormat.format(interval));
1431     }
1432 
1433     @Test(expected = UnsupportedOperationException.class)
testParseObject_notSupported()1434     public void testParseObject_notSupported() throws ParseException {
1435         DateIntervalFormat.getInstance(DateFormat.YEAR_MONTH).parseObject("");
1436     }
1437 
1438     @Test
TestDateIntervalFormatCoverage()1439     public void TestDateIntervalFormatCoverage() throws Exception{
1440         long date1 = 1299090600000L;
1441         long date2 = 1299115800000L;
1442         DateInterval dtitv = new DateInterval(date1, date2);
1443         DateIntervalFormat dtitvfmt = DateIntervalFormat.getInstance("MMMd", Locale.ENGLISH);
1444         DateIntervalInfo dtintinf = new DateIntervalInfo(ULocale.ENGLISH);
1445 
1446         // Check the default private constructor
1447         checkDefaultPrivateConstructor(DateIntervalFormat.class);
1448 
1449         // Check clone
1450         DateIntervalFormat dtitvfmtClone = (DateIntervalFormat) dtitvfmt.clone();
1451         assertEquals("DateIntervalFormat.clone() failed", dtitvfmt.format(dtitv), dtitvfmtClone.format(dtitv));
1452 
1453         // Coverage for getInstance
1454         assertNotNull("Expected DateIntervalFormat object", DateIntervalFormat.getInstance("MMMd", dtintinf));
1455         assertNotNull("Expected DateIntervalFormat object",
1456                 DateIntervalFormat.getInstance("MMMdHHmm", Locale.ENGLISH, dtintinf));
1457 
1458         // Coverage for parseObject. Exception expected.
1459         try {
1460             dtitvfmt.parseObject("", new ParsePosition(0));
1461             errln("Exception was expected when calling DateIntervalFormat.parseObject()");
1462         } catch (Exception e) { /* No op */ }
1463 
1464         // Check getPatterns()
1465         Output<String> secondPart = new Output<>();
1466         Calendar fromCalendar = Calendar.getInstance(Locale.ENGLISH);
1467         fromCalendar.set(2016, 5, 22);
1468         Calendar toCalendar= Calendar.getInstance(Locale.ENGLISH);
1469         toCalendar.set(2016, 5, 23);
1470         assertEquals("Date interval pattern mismatch.",
1471                 dtitvfmt.getPatterns(fromCalendar, toCalendar, secondPart), "MMM d – ");
1472         assertEquals("Date interval pattern mismatch.", secondPart.value, "d");
1473     }
1474 
1475     @Test
TestTicket9919GetInstance()1476     public void TestTicket9919GetInstance() {
1477         // Creating a DateIntervalFormat with a custom DateIntervalInfo
1478         // object used to corrupt the cache.
1479         DateIntervalFormat dif = DateIntervalFormat.getInstance(
1480                 "yMd", ULocale.ENGLISH);
1481         Calendar from = Calendar.getInstance();
1482         Calendar to = Calendar.getInstance();
1483         from.set(2013, 3, 26);
1484         to.set(2013, 3, 28);
1485 
1486         // Save. This is the correct answer
1487         String expected =
1488                 dif.format(from, to, new StringBuffer(), new FieldPosition(0))
1489                 .toString();
1490 
1491         // Now create a DateIntervalFormat with same skeleton and
1492         // locale, but with a custom DateIntervalInfo. This used
1493         // to corrupt the cache.
1494         DateIntervalInfo dateIntervalInfo =
1495                 new DateIntervalInfo(ULocale.ENGLISH);
1496         dateIntervalInfo.setIntervalPattern(
1497                 "yMd", Calendar.DATE, "M/d/y \u2013 d");
1498         DateIntervalFormat.getInstance(
1499                 "yMd", ULocale.ENGLISH, dateIntervalInfo);
1500 
1501         // Now create a DateIntervalFormat with same skeleton and
1502         // locale, but with default DateIntervalInfo. The cache should
1503         // not be corrupted, and we should get the same answer as before.
1504         dif = DateIntervalFormat.getInstance("yMd", ULocale.ENGLISH);
1505 
1506         assertEquals(
1507                 "Custom DateIntervalInfo objects should not mess up cache",
1508                 expected,
1509                 dif.format(from, to, new StringBuffer(), new FieldPosition(0))
1510                 .toString());
1511 
1512     }
1513 
1514     @Test
TestTicket9919Setter()1515     public void TestTicket9919Setter() {
1516 
1517         // Creating a DateIntervalFormat with a custom DateIntervalInfo
1518         // object used to corrupt the cache.
1519         DateIntervalFormat dif = DateIntervalFormat.getInstance(
1520                 "yMd", ULocale.ENGLISH);
1521         Calendar from = Calendar.getInstance();
1522         Calendar to = Calendar.getInstance();
1523         from.set(2013, 3, 26);
1524         to.set(2013, 3, 28);
1525 
1526         // Save. This is the correct answer
1527         String expected =
1528                 dif.format(from, to, new StringBuffer(), new FieldPosition(0))
1529                 .toString();
1530 
1531         // Now create a DateIntervalFormat with same skeleton and
1532         // locale, but with a custom DateIntervalInfo. This used
1533         // to corrupt the cache.
1534         DateIntervalInfo dateIntervalInfo =
1535                 new DateIntervalInfo(ULocale.ENGLISH);
1536         dateIntervalInfo.setIntervalPattern(
1537                 "yMd", Calendar.DATE, "M/d/y \u2013 d");
1538         DateIntervalFormat bad = DateIntervalFormat.getInstance(
1539                 "yMd", ULocale.ENGLISH);
1540         bad.setDateIntervalInfo(dateIntervalInfo);
1541 
1542         // Now create a DateIntervalFormat with same skeleton and
1543         // locale, but with default DateIntervalInfo. The cache should
1544         // not be corrupted, and we should get the same answer as before.
1545         dif = DateIntervalFormat.getInstance("yMd", ULocale.ENGLISH);
1546         assertEquals(
1547                 "Custom DateIntervalInfo objects should not mess up cache",
1548                 expected,
1549                 dif.format(from, to, new StringBuffer(), new FieldPosition(0))
1550                 .toString());
1551     }
1552 
1553     @Test
TestTicket9914()1554     public void TestTicket9914() {
1555         DateIntervalInfo dateIntervalInfo =
1556                 new DateIntervalInfo(ULocale.ENGLISH);
1557 
1558         Calendar from = Calendar.getInstance();
1559         Calendar to = Calendar.getInstance();
1560         from.set(113, 3, 26);
1561         to.set(113, 3, 28);
1562         DateIntervalFormat dif = DateIntervalFormat.getInstance(
1563                 "yyyyMd", ULocale.ENGLISH, dateIntervalInfo);
1564         assertEquals(
1565                 "yyyyMd skeleton.",
1566                 "4/26/0113 \u2013 4/28/0113",
1567                 dif.format(from, to, new StringBuffer(), new FieldPosition(0))
1568                 .toString());
1569 
1570         dif = DateIntervalFormat.getInstance(
1571                 "yyMd", ULocale.ENGLISH, dateIntervalInfo);
1572         assertEquals(
1573                 "yyMd skeleton.",
1574                 "4/26/13 \u2013 4/28/13",
1575                 dif.format(from, to, new StringBuffer(), new FieldPosition(0))
1576                 .toString());
1577 
1578         dif = DateIntervalFormat.getInstance(
1579                 "yMd", ULocale.ENGLISH, dateIntervalInfo);
1580         assertEquals(
1581                 "yMd skeleton.",
1582                 "4/26/113 \u2013 4/28/113",
1583                 dif.format(from, to, new StringBuffer(), new FieldPosition(0))
1584                 .toString());
1585     }
1586 
1587     @Test
TestTicket11583()1588     public void TestTicket11583 () {
1589         ULocale[] locales = {
1590                 ULocale.ENGLISH,
1591                 SPANISH,
1592                 LA_SPANISH,
1593                 };
1594         String[] skeletons = {
1595                 "yMMMMd", "yMMMM", "MMMM",
1596                 "yMMMd", "yMMM", "MMM",
1597                 "yMMd", "yMMdd", "yMM", "MM",
1598                 "yMdd", "yMd", "yM", "M"
1599                 };
1600 
1601         final long startDate = 1232364615000L;
1602         final long endDate = 1240399815000L;
1603         String filterPattern = null ; // "yMMM";
1604 
1605         for (ULocale locale : locales) {
1606             for (String skeleton : skeletons) {
1607                 if (filterPattern != null && !skeleton.equals(filterPattern)) {
1608                     continue;
1609                 }
1610 
1611                 DateFormat dateFormat = DateFormat.getPatternInstance(skeleton, locale);
1612                 String dateFormatPattern = ((SimpleDateFormat)dateFormat).toPattern();
1613 
1614                 DateIntervalFormat intervalFormat = DateIntervalFormat.getInstance(skeleton, locale);
1615                 DateIntervalInfo intervalInfo = intervalFormat.getDateIntervalInfo();
1616 
1617                 if (skeleton.equals(filterPattern)) {
1618                     logln(filterPattern + " => " + intervalInfo.getRawPatterns().get(filterPattern));
1619                 }
1620 
1621                 DateInterval date_interval = new DateInterval(startDate, endDate);
1622 
1623                 String interval = intervalFormat.format(date_interval);
1624 
1625                 String formattedStart = dateFormat.format(startDate);
1626                 String formattedEnd = dateFormat.format(endDate);
1627 
1628                 PatternInfo patternInfo = intervalFormat.getRawPatterns().get("M");
1629 
1630                 String firstPart = patternInfo.getFirstPart();
1631                 String secondPart = patternInfo.getSecondPart();
1632                 if (!matches(dateFormatPattern, firstPart, secondPart)) {
1633                     if (logKnownIssue("11585", "incompatible pattern between date format and date interval format")) {
1634                         logln("For skeleton " + skeleton + "/locale " + locale + ": mismatch between date format «"
1635                                 + dateFormatPattern + "» and date interval format «" + firstPart + secondPart + "».");
1636                     } else {
1637                         errln("For skeleton " + skeleton + "/locale " + locale + ": mismatch between date format «"
1638                                 + dateFormatPattern + "» and date interval format «" + firstPart + secondPart + "».");
1639                     }
1640                 }
1641 
1642                 logln(locale
1643                         + "\tskeleton: «" + skeleton
1644                         + "»\tpattern: «" + dateFormatPattern
1645                         + "»\tintervalPattern1: «" + firstPart
1646                         + "»\tintervalPattern2: «" + secondPart
1647                         + "»\tstartDate: «" + formattedStart
1648                         + "»\tendDate: «" + formattedEnd
1649                         + "»\tinterval: «" + interval
1650                         + "»"
1651                         );
1652             }
1653         }
1654     }
1655 
1656 
1657     /**
1658      * Return true if for some x, y: dateFormatPattern = firstPart(0,x) + secondPart(y, secondPart.length())
1659      * @param dateFormatPattern
1660      * @param firstPart
1661      * @param secondPart
1662      * @return
1663      */
matches(String dateFormatPattern, String firstPart, String secondPart)1664     private boolean matches(String dateFormatPattern, String firstPart, String secondPart) {
1665         // brute force for now
1666         int lastButOne = dateFormatPattern.length()-1;
1667         for (int i = 1; i < lastButOne; ++i) {
1668             if (firstPart.startsWith(dateFormatPattern.substring(0,i))
1669                     && secondPart.endsWith(dateFormatPattern.substring(i,dateFormatPattern.length()))) {
1670                 return true;
1671             }
1672         }
1673         return false;
1674     }
1675 
1676     @Test
TestFPos_SkelWithSeconds()1677     public void TestFPos_SkelWithSeconds () {
1678 
1679         final long[] deltas = {
1680 	        0L, // none
1681 	        200L, // 200 millisec
1682 	        20000L, // 20 sec
1683 	        1200000L, // 20 min
1684 	        7200000L, // 2 hrs
1685 	        43200000L, // 12 hrs
1686 	        691200000L, // 8 days
1687 	        1382400000L, // 16 days,
1688 	        8640000000L, // 100 days
1689         };
1690 
1691         class ExpectPosAndFormat {
1692             public int posBegin;
1693             public int posEnd;
1694             public String format;
1695              // Simple constructor
1696             public ExpectPosAndFormat(int pBegin, int pEnd, String fmt) {
1697                 posBegin = pBegin;
1698                 posEnd = pEnd;
1699                 format = fmt;
1700             }
1701         };
1702 
1703         final ExpectPosAndFormat[] exp_en_HHmm = {
1704             new ExpectPosAndFormat(  3,  5, "09:00" ),
1705             new ExpectPosAndFormat(  3,  5, "09:00" ),
1706             new ExpectPosAndFormat(  3,  5, "09:00" ),
1707             new ExpectPosAndFormat(  3,  5, "09:00 \u2013 09:20" ),
1708             new ExpectPosAndFormat(  3,  5, "09:00 \u2013 11:00" ),
1709             new ExpectPosAndFormat(  3,  5, "09:00 \u2013 21:00" ),
1710             new ExpectPosAndFormat( 15, 17, "11/20/2014, 09:00 \u2013 11/28/2014, 09:00" ),
1711             new ExpectPosAndFormat( 15, 17, "11/20/2014, 09:00 \u2013 12/6/2014, 09:00" ),
1712             new ExpectPosAndFormat( 15, 17, "11/20/2014, 09:00 \u2013 2/28/2015, 09:00" )
1713         };
1714 
1715         final ExpectPosAndFormat[] exp_en_HHmmss = {
1716             new ExpectPosAndFormat(  3,  5, "09:00:00" ),
1717             new ExpectPosAndFormat(  3,  5, "09:00:00" ),
1718             new ExpectPosAndFormat(  3,  5, "09:00:00 \u2013 09:00:20" ),
1719             new ExpectPosAndFormat(  3,  5, "09:00:00 \u2013 09:20:00" ),
1720             new ExpectPosAndFormat(  3,  5, "09:00:00 \u2013 11:00:00" ),
1721             new ExpectPosAndFormat(  3,  5, "09:00:00 \u2013 21:00:00" ),
1722             new ExpectPosAndFormat( 15, 17, "11/20/2014, 09:00:00 \u2013 11/28/2014, 09:00:00" ),
1723             new ExpectPosAndFormat( 15, 17, "11/20/2014, 09:00:00 \u2013 12/6/2014, 09:00:00" ),
1724             new ExpectPosAndFormat( 15, 17, "11/20/2014, 09:00:00 \u2013 2/28/2015, 09:00:00" )
1725         };
1726 
1727         final ExpectPosAndFormat[] exp_en_yyMMdd = {
1728             new ExpectPosAndFormat(  0,  0, "11/20/14" ),
1729             new ExpectPosAndFormat(  0,  0, "11/20/14" ),
1730             new ExpectPosAndFormat(  0,  0, "11/20/14" ),
1731             new ExpectPosAndFormat(  0,  0, "11/20/14" ),
1732             new ExpectPosAndFormat(  0,  0, "11/20/14" ),
1733             new ExpectPosAndFormat(  0,  0, "11/20/14" ),
1734             new ExpectPosAndFormat(  0,  0, "11/20/14 \u2013 11/28/14" ),
1735             new ExpectPosAndFormat(  0,  0, "11/20/14 \u2013 12/6/14" ),
1736             new ExpectPosAndFormat(  0,  0, "11/20/14 \u2013 2/28/15" )
1737         };
1738 
1739         final ExpectPosAndFormat[] exp_en_yyMMddHHmm = {
1740             new ExpectPosAndFormat( 13, 15, "11/20/14, 09:00" ),
1741             new ExpectPosAndFormat( 13, 15, "11/20/14, 09:00" ),
1742             new ExpectPosAndFormat( 13, 15, "11/20/14, 09:00" ),
1743             new ExpectPosAndFormat( 13, 15, "11/20/14, 09:00 \u2013 09:20" ),
1744             new ExpectPosAndFormat( 13, 15, "11/20/14, 09:00 \u2013 11:00" ),
1745             new ExpectPosAndFormat( 13, 15, "11/20/14, 09:00 \u2013 21:00" ),
1746             new ExpectPosAndFormat( 13, 15, "11/20/14, 09:00 \u2013 11/28/14, 09:00" ),
1747             new ExpectPosAndFormat( 13, 15, "11/20/14, 09:00 \u2013 12/06/14, 09:00" ),
1748             new ExpectPosAndFormat( 13, 15, "11/20/14, 09:00 \u2013 02/28/15, 09:00" )
1749         };
1750 
1751         final ExpectPosAndFormat[] exp_en_yyMMddHHmmss = {
1752             new ExpectPosAndFormat( 13, 15, "11/20/14, 09:00:00" ),
1753             new ExpectPosAndFormat( 13, 15, "11/20/14, 09:00:00" ),
1754             new ExpectPosAndFormat( 13, 15, "11/20/14, 09:00:00 \u2013 09:00:20" ),
1755             new ExpectPosAndFormat( 13, 15, "11/20/14, 09:00:00 \u2013 09:20:00" ),
1756             new ExpectPosAndFormat( 13, 15, "11/20/14, 09:00:00 \u2013 11:00:00" ),
1757             new ExpectPosAndFormat( 13, 15, "11/20/14, 09:00:00 \u2013 21:00:00" ),
1758             new ExpectPosAndFormat( 13, 15, "11/20/14, 09:00:00 \u2013 11/28/14, 09:00:00" ),
1759             new ExpectPosAndFormat( 13, 15, "11/20/14, 09:00:00 \u2013 12/06/14, 09:00:00" ),
1760             new ExpectPosAndFormat( 13, 15, "11/20/14, 09:00:00 \u2013 02/28/15, 09:00:00" )
1761         };
1762 
1763         @SuppressWarnings("unused")
1764         final ExpectPosAndFormat[] exp_en_yMMMdhmmssz = {
1765             new ExpectPosAndFormat( 16, 18, "Nov 20, 2014, 9:00:00 AM GMT" ),
1766             new ExpectPosAndFormat( 16, 18, "Nov 20, 2014, 9:00:00 AM GMT" ),
1767             new ExpectPosAndFormat( 16, 18, "Nov 20, 2014, 9:00:00 AM GMT \u2013 9:00:20 AM GMT" ),
1768             new ExpectPosAndFormat( 16, 18, "Nov 20, 2014, 9:00:00 AM GMT \u2013 9:20:00 AM GMT" ),
1769             new ExpectPosAndFormat( 16, 18, "Nov 20, 2014, 9:00:00 AM GMT \u2013 11:00:00 AM GMT" ),
1770             new ExpectPosAndFormat( 16, 18, "Nov 20, 2014, 9:00:00 AM GMT \u2013 9:00:00 PM GMT" ),
1771             new ExpectPosAndFormat( 16, 18, "Nov 20, 2014, 9:00:00 AM GMT \u2013 Nov 28, 2014, 9:00:00 AM GMT" ),
1772             new ExpectPosAndFormat( 16, 18, "Nov 20, 2014, 9:00:00 AM GMT \u2013 Dec 6, 2014, 9:00:00 AM GMT" ),
1773             new ExpectPosAndFormat( 16, 18, "Nov 20, 2014, 9:00:00 AM GMT \u2013 Feb 28, 2015, 9:00:00 AM GMT" )
1774         };
1775 
1776         final ExpectPosAndFormat[] exp_ja_yyMMddHHmm = {
1777             new ExpectPosAndFormat( 11, 13, "14/11/20 9:00" ),
1778             new ExpectPosAndFormat( 11, 13, "14/11/20 9:00" ),
1779             new ExpectPosAndFormat( 11, 13, "14/11/20 9:00" ),
1780             new ExpectPosAndFormat( 11, 13, "14/11/20 9\u664200\u5206\uFF5E9\u664220\u5206" ),
1781             new ExpectPosAndFormat( 11, 13, "14/11/20 9\u664200\u5206\uFF5E11\u664200\u5206" ),
1782             new ExpectPosAndFormat( 11, 13, "14/11/20 9\u664200\u5206\uFF5E21\u664200\u5206" ),
1783             new ExpectPosAndFormat( 11, 13, "14/11/20 9:00\uFF5E14/11/28 9:00" ),
1784             new ExpectPosAndFormat( 11, 13, "14/11/20 9:00\uFF5E14/12/06 9:00" ),
1785             new ExpectPosAndFormat( 11, 13, "14/11/20 9:00\uFF5E15/02/28 9:00" )
1786         };
1787 
1788         final ExpectPosAndFormat[] exp_ja_yyMMddHHmmss = {
1789             new ExpectPosAndFormat( 11, 13, "14/11/20 9:00:00" ),
1790             new ExpectPosAndFormat( 11, 13, "14/11/20 9:00:00" ),
1791             new ExpectPosAndFormat( 11, 13, "14/11/20 9:00:00\uFF5E9:00:20" ),
1792             new ExpectPosAndFormat( 11, 13, "14/11/20 9:00:00\uFF5E9:20:00" ),
1793             new ExpectPosAndFormat( 11, 13, "14/11/20 9:00:00\uFF5E11:00:00" ),
1794             new ExpectPosAndFormat( 11, 13, "14/11/20 9:00:00\uFF5E21:00:00" ),
1795             new ExpectPosAndFormat( 11, 13, "14/11/20 9:00:00\uFF5E14/11/28 9:00:00" ),
1796             new ExpectPosAndFormat( 11, 13, "14/11/20 9:00:00\uFF5E14/12/06 9:00:00" ),
1797             new ExpectPosAndFormat( 11, 13, "14/11/20 9:00:00\uFF5E15/02/28 9:00:00" )
1798         };
1799 
1800         final ExpectPosAndFormat[] exp_ja_yMMMdHHmmss = {
1801             new ExpectPosAndFormat( 14, 16, "2014\u5E7411\u670820\u65E5 9:00:00" ),
1802             new ExpectPosAndFormat( 14, 16, "2014\u5E7411\u670820\u65E5 9:00:00" ),
1803             new ExpectPosAndFormat( 14, 16, "2014\u5E7411\u670820\u65E5 9:00:00\uFF5E9:00:20" ),
1804             new ExpectPosAndFormat( 14, 16, "2014\u5E7411\u670820\u65E5 9:00:00\uFF5E9:20:00" ),
1805             new ExpectPosAndFormat( 14, 16, "2014\u5E7411\u670820\u65E5 9:00:00\uFF5E11:00:00" ),
1806             new ExpectPosAndFormat( 14, 16, "2014\u5E7411\u670820\u65E5 9:00:00\uFF5E21:00:00" ),
1807             new ExpectPosAndFormat( 14, 16, "2014\u5E7411\u670820\u65E5 9:00:00\uFF5E2014\u5E7411\u670828\u65E5 9:00:00" ),
1808             new ExpectPosAndFormat( 14, 16, "2014\u5E7411\u670820\u65E5 9:00:00\uFF5E2014\u5E7412\u67086\u65E5 9:00:00" ),
1809             new ExpectPosAndFormat( 14, 16, "2014\u5E7411\u670820\u65E5 9:00:00\uFF5E2015\u5E742\u670828\u65E5 9:00:00" )
1810         };
1811 
1812         class LocaleAndSkeletonItem {
1813             public String locale;
1814             public String skeleton;
1815             public int fieldToCheck;
1816             public ExpectPosAndFormat[] expected;
1817              // Simple constructor
1818             public LocaleAndSkeletonItem(String loc, String skel, int field, ExpectPosAndFormat[] exp) {
1819                 locale = loc;
1820                 skeleton = skel;
1821                 fieldToCheck = field;
1822                 expected = exp;
1823             }
1824         };
1825 
1826         final LocaleAndSkeletonItem[] locSkelItems = {
1827            new LocaleAndSkeletonItem( "en",		"HHmm",         DateFormat.MINUTE_FIELD, exp_en_HHmm ),
1828            new LocaleAndSkeletonItem( "en",		"HHmmss",       DateFormat.MINUTE_FIELD, exp_en_HHmmss ),
1829            new LocaleAndSkeletonItem( "en",		"yyMMdd",       DateFormat.MINUTE_FIELD, exp_en_yyMMdd ),
1830            new LocaleAndSkeletonItem( "en",		"yyMMddHHmm",   DateFormat.MINUTE_FIELD, exp_en_yyMMddHHmm ),
1831            new LocaleAndSkeletonItem( "en",		"yyMMddHHmmss", DateFormat.MINUTE_FIELD, exp_en_yyMMddHHmmss ),
1832         // skip the following until ICU4J DateIntervalFormat has support for setting time zone
1833         // new LocaleAndSkeletonItem( "en",		"yMMMdhmmssz",  DateFormat.MINUTE_FIELD, exp_en_yMMMdhmmssz ),
1834            new LocaleAndSkeletonItem( "ja",		"yyMMddHHmm",   DateFormat.MINUTE_FIELD, exp_ja_yyMMddHHmm ),
1835            new LocaleAndSkeletonItem( "ja",		"yyMMddHHmmss", DateFormat.MINUTE_FIELD, exp_ja_yyMMddHHmmss ),
1836            new LocaleAndSkeletonItem( "ja",		"yMMMdHHmmss",  DateFormat.MINUTE_FIELD, exp_ja_yMMMdHHmmss )
1837         };
1838 
1839         //final String zoneGMT = "GMT";
1840         final long startTimeGMT = 1416474000000L; // 2014 Nov 20 09:00 GMT
1841 
1842         TimeZone localZone = TimeZone.getDefault();
1843         long startTime = startTimeGMT - localZone.getOffset(startTimeGMT);
1844         for (LocaleAndSkeletonItem item: locSkelItems) {
1845             DateIntervalFormat difmt = DateIntervalFormat.getInstance(item.skeleton, new ULocale(item.locale));
1846             int dIdx, dCount = deltas.length;
1847             for (dIdx = 0; dIdx < dCount; dIdx++) {
1848                 DateInterval di = new DateInterval(startTime, startTime + deltas[dIdx]);
1849                 StringBuffer actual = new StringBuffer(64);
1850                 FieldPosition pos = new FieldPosition(item.fieldToCheck);
1851                 String actualString = difmt.format(di, actual, pos).toString();
1852                 ExpectPosAndFormat expectPosFmt = item.expected[dIdx];
1853                 if (!actualString.equals(expectPosFmt.format) ||
1854                         pos.getBeginIndex() != expectPosFmt.posBegin || pos.getEndIndex() != expectPosFmt.posEnd) {
1855                     errln("For locale " + item.locale + ", skeleton " + item.skeleton + ", delta " + deltas[dIdx] +
1856                            ": expect " + expectPosFmt.posBegin + "-" + expectPosFmt.posEnd + " \"" + expectPosFmt.format +
1857                            "\"; get " + pos.getBeginIndex() + "-" + pos.getEndIndex() + " \"" + actualString + "\"");
1858                 }
1859             }
1860         }
1861     }
1862 
1863     // TestTicket11669 - Check the thread safety of DateIntervalFormat.format().
1864     //                   This test failed with ICU 56.
1865     @Test
TestTicket11669()1866     public void TestTicket11669 () {
1867         // These final variables are accessed directly by the concurrent threads.
1868         final DateIntervalFormat formatter = DateIntervalFormat.getInstance(DateFormat.YEAR_MONTH_DAY, ULocale.US);
1869         final ArrayList<DateInterval> testIntervals = new ArrayList<>();
1870         final ArrayList<String>expectedResults = new ArrayList<>();
1871 
1872         // Create and save the input test data.
1873         TimeZone tz = TimeZone.getTimeZone("Americal/Los_Angeles");
1874         Calendar intervalStart = Calendar.getInstance(tz, ULocale.US);
1875         Calendar intervalEnd = Calendar.getInstance(tz, ULocale.US);
1876         intervalStart.set(2009,  6, 1);
1877         intervalEnd.set(2009, 6, 2);
1878         testIntervals.add(new DateInterval(intervalStart.getTimeInMillis(), intervalEnd.getTimeInMillis()));
1879         intervalStart.set(2015, 2, 27);
1880         intervalEnd.set(2015, 3, 1);
1881         testIntervals.add(new DateInterval(intervalStart.getTimeInMillis(), intervalEnd.getTimeInMillis()));
1882 
1883         // Run the formatter single-threaded to create and save the expected results.
1884         for (DateInterval interval: testIntervals) {
1885             FieldPosition pos = new FieldPosition(0);
1886             StringBuffer result = new StringBuffer();
1887             formatter.format(interval, result, pos);
1888             expectedResults.add(result.toString());
1889         }
1890 
1891         class TestThread extends Thread {
1892             public String errorMessage;
1893             @Override
1894             public void run() {
1895                 for (int loop=0; loop < 2000; ++loop) {
1896                     ListIterator<String> expectedItr = expectedResults.listIterator();
1897                     for (DateInterval interval: testIntervals) {
1898                         String expected = expectedItr.next();
1899                         FieldPosition pos = new FieldPosition(0);
1900                         StringBuffer result = new StringBuffer();
1901                         formatter.format(interval, result, pos);
1902                         if (!expected.equals(result.toString())) {
1903                             // Note: The ICU test framework doesn't support reporting failures from within a sub-thread.
1904                             //       Save the failure for the main thread to pick up later.
1905                             errorMessage = String.format("Expected \"%s\", actual \"%s\"", expected, result);
1906                             return;
1907                         }
1908                     }
1909                 }
1910             }
1911         }
1912 
1913         List<TestThread> threads = new ArrayList<>();
1914         for (int i=0; i<4; ++i) {
1915             threads.add(new TestThread());
1916         }
1917         for (Thread t: threads) {
1918             t.start();
1919         }
1920         for (TestThread t: threads) {
1921             try {
1922                 t.join();
1923             } catch (InterruptedException e) {
1924                 fail("Unexpected exception: " + e.toString());
1925             }
1926             if (t.errorMessage != null) {
1927                 fail(t.errorMessage);
1928             }
1929         }
1930     }
1931 
1932     @Test
testFormattedDateInterval()1933     public void testFormattedDateInterval() {
1934         DateIntervalFormat fmt = DateIntervalFormat.getInstance("dMMMMy", ULocale.US);
1935 
1936         {
1937             String message = "FormattedDateInterval test 1";
1938             String expectedString = "July 20 \u2013 25, 2018";
1939             Calendar input1 = Calendar.getInstance(ULocale.UK);
1940             Calendar input2 = Calendar.getInstance(ULocale.UK);
1941             input1.set(2018, 6, 20);
1942             input2.set(2018, 6, 25);
1943             FormattedDateInterval result = fmt.formatToValue(input1, input2);
1944             Object[][] expectedFieldPositions = new Object[][] {
1945                 // field, begin index, end index
1946                 {DateFormat.Field.MONTH, 0, 4},
1947                 {DateIntervalFormat.SpanField.DATE_INTERVAL_SPAN, 5, 7, 0},
1948                 {DateFormat.Field.DAY_OF_MONTH, 5, 7},
1949                 {DateIntervalFormat.SpanField.DATE_INTERVAL_SPAN, 10, 12, 1},
1950                 {DateFormat.Field.DAY_OF_MONTH, 10, 12},
1951                 {DateFormat.Field.YEAR, 14, 18}};
1952             FormattedValueTest.checkFormattedValue(
1953                 message,
1954                 result,
1955                 expectedString,
1956                 expectedFieldPositions);
1957         }
1958 
1959         // Test sample code
1960         {
1961             Calendar input1 = Calendar.getInstance(ULocale.UK);
1962             Calendar input2 = Calendar.getInstance(ULocale.UK);
1963             input1.set(2018, 6, 20);
1964             input2.set(2018, 7, 3);
1965 
1966             // Let fmt be a DateIntervalFormat for locale en-US and skeleton dMMMMy
1967             // Let input1 be July 20, 2018 and input2 be August 3, 2018:
1968             FormattedDateInterval result = fmt.formatToValue(input1, input2);
1969             assertEquals("Expected output from format",
1970                 "July 20 \u2013 August 3, 2018", result.toString());
1971             ConstrainedFieldPosition cfpos = new ConstrainedFieldPosition();
1972             cfpos.constrainFieldAndValue(DateIntervalFormat.SpanField.DATE_INTERVAL_SPAN, 0);
1973             if (result.nextPosition(cfpos)) {
1974                 assertEquals("Expect start index", 0, cfpos.getStart());
1975                 assertEquals("Expect end index", 7, cfpos.getLimit());
1976             } else {
1977                 // No such span: can happen if input dates are equal.
1978             }
1979             assertFalse("No more than one occurrence of the field",
1980                 result.nextPosition(cfpos));
1981         }
1982 
1983         fmt = DateIntervalFormat.getInstance("dMMMha", ULocale.US);
1984 
1985         {
1986             String message = "FormattedDateInterval test 2";
1987             String expectedString = "Feb 15, 11 AM \u2013 3 PM";
1988             Calendar input1 = Calendar.getInstance(ULocale.US);
1989             Calendar input2 = Calendar.getInstance(ULocale.US);
1990             input1.set(2019, 1, 15, 11, 0, 0);
1991             input2.set(2019, 1, 15, 15, 0, 0);
1992             FormattedDateInterval result = fmt.formatToValue(input1, input2);
1993             Object[][] expectedFieldPositions = new Object[][] {
1994                 // field, begin index, end index
1995                 {DateFormat.Field.MONTH, 0, 3},
1996                 {DateFormat.Field.DAY_OF_MONTH, 4, 6},
1997                 {DateIntervalFormat.SpanField.DATE_INTERVAL_SPAN, 8, 13, 0},
1998                 {DateFormat.Field.HOUR1, 8, 10},
1999                 {DateFormat.Field.AM_PM, 11, 13},
2000                 {DateIntervalFormat.SpanField.DATE_INTERVAL_SPAN, 16, 20, 1},
2001                 {DateFormat.Field.HOUR1, 16, 17},
2002                 {DateFormat.Field.AM_PM, 18, 20}};
2003             FormattedValueTest.checkFormattedValue(
2004                 message,
2005                 result,
2006                 expectedString,
2007                 expectedFieldPositions);
2008         }
2009 
2010         // To test the fallback pattern behavior, make a custom DateIntervalInfo.
2011         DateIntervalInfo dtitvinf = new DateIntervalInfo();
2012         dtitvinf.setFallbackIntervalPattern("<< {1} --- {0} >>");
2013         fmt = DateIntervalFormat.getInstance("dMMMMy", ULocale.US, dtitvinf);
2014 
2015         {
2016             String message = "FormattedDateInterval with fallback format test 1";
2017             String expectedString = "<< July 25, 2018 --- July 20, 2018 >>";
2018             Date input1 = new Date(2018 - 1900, 6, 20);
2019             Date input2 = new Date(2018 - 1900, 6, 25);
2020             DateInterval dtiv = new DateInterval(input1.getTime(), input2.getTime());
2021             FormattedDateInterval result = fmt.formatToValue(dtiv);
2022             Object[][] expectedFieldPositions = new Object[][] {
2023                 {DateIntervalFormat.SpanField.DATE_INTERVAL_SPAN, 3, 16, 1},
2024                 {DateFormat.Field.MONTH, 3, 7},
2025                 {DateFormat.Field.DAY_OF_MONTH, 8, 10},
2026                 {DateFormat.Field.YEAR, 12, 16},
2027                 {DateIntervalFormat.SpanField.DATE_INTERVAL_SPAN, 21, 34, 0},
2028                 {DateFormat.Field.MONTH, 21, 25},
2029                 {DateFormat.Field.DAY_OF_MONTH, 26, 28},
2030                 {DateFormat.Field.YEAR, 30, 34}};
2031             FormattedValueTest.checkFormattedValue(
2032                 message,
2033                 result,
2034                 expectedString,
2035                 expectedFieldPositions);
2036         }
2037     }
2038     @Test
testCreateInstanceForAllLocales()2039     public void testCreateInstanceForAllLocales() {
2040         boolean quick = (getExhaustiveness() <= 5);
2041         int count = 0;
2042         for (ULocale locale : ULocale.getAvailableLocalesByType(
2043                 ULocale.AvailableType.WITH_LEGACY_ALIASES)) {
2044             // Only test 1/5 of the locale in quick mode.
2045             if (quick && (count++ % 5 > 0)) continue;
2046             DateIntervalFormat fmt = DateIntervalFormat.getInstance("dMMMMy", locale);
2047             for (String calendar : Calendar.getKeywordValuesForLocale(
2048                     "calendar", locale, false)) {
2049                 // Only test 1/7 of case in quick mode.
2050                 if (quick && (count++ % 7 > 0)) continue;
2051                 ULocale l = locale.setKeywordValue("calendar", calendar);
2052                 fmt = DateIntervalFormat.getInstance("dMMMMy", l);
2053             }
2054         }
2055     }
2056 
2057     @Test
testTicket20707()2058     public void testTicket20707() {
2059         TimeZone tz = TimeZone.getTimeZone("UTC");
2060         Locale locales[] = {
2061             new Locale("en-u-hc-h24"),
2062             new Locale("en-u-hc-h23"),
2063             new Locale("en-u-hc-h12"),
2064             new Locale("en-u-hc-h11"),
2065             new Locale("en"),
2066             new Locale("en-u-hc-h25"),
2067             //new Locale("hi-IN-u-hc-h11")
2068         };
2069 
2070         // Clomuns: hh, HH, kk, KK, jj, JJs, CC
2071         String expected[][] = {
2072             // Hour-cycle: k
2073             {"12 AM", "24", "24", "12 AM", "24", "0 (hour: 24)", "12 AM"},
2074             // Hour-cycle: H
2075             {"12 AM", "00", "00", "12 AM", "00", "0 (hour: 00)", "12 AM"},
2076             // Hour-cycle: h
2077             {"12 AM", "00", "00", "12 AM", "12 AM", "0 (hour: 12)", "12 AM"},
2078             // Hour-cycle: K
2079             {"0 AM", "00", "00", "0 AM", "0 AM", "0 (hour: 00)", "0 AM"},
2080             {"12 AM", "00", "00", "12 AM", "12 AM", "0 (hour: 12)", "12 AM"},
2081             {"12 AM", "00", "00", "12 AM", "12 AM", "0 (hour: 12)", "12 AM"},
2082             //{"0 am", "00", "00", "0 am", "0 am", "0 (\u0918\u0902\u091F\u093E: 00)", "\u0930\u093E\u0924 0"}
2083         };
2084 
2085         int i = 0;
2086         for (Locale locale : locales) {
2087             int j = 0;
2088             String skeletons[] = {"hh", "HH", "kk", "KK", "jj", "JJs", "CC"};
2089             for (String skeleton : skeletons) {
2090                 DateIntervalFormat dateFormat = DateIntervalFormat.getInstance(skeleton, locale);
2091                 Calendar calendar = Calendar.getInstance(tz);
2092                 calendar.setTime(new Date(1563235200000L));
2093                 StringBuffer resultBuffer = dateFormat.format(calendar, calendar, new StringBuffer(""), new FieldPosition(0));
2094 
2095                 assertEquals("Formatted result for " + skeleton + " locale: " + locale.getDisplayName(), expected[i][j++], resultBuffer.toString());
2096             }
2097             i++;
2098         }
2099     }
2100 
2101     @Test
testFormatMillisecond()2102     public void testFormatMillisecond() {
2103         Object[][] kTestCases = {
2104             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 1, 23, 45), 321, "ms",     "23:45"},
2105             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 1, 23, 45), 321, "msS",    "23:45.3"},
2106             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 1, 23, 45), 321, "msSS",   "23:45.32"},
2107             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 1, 23, 45), 321, "msSSS",  "23:45.321"},
2108             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 1, 23, 45), 987, "ms",     "23:45"},
2109             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 1, 23, 45), 987, "msS",    "23:45.3 – 23:45.9"},
2110             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 1, 23, 45), 987, "msSS",   "23:45.32 – 23:45.98"},
2111             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 1, 23, 45), 987, "msSSS",  "23:45.321 – 23:45.987"},
2112             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 1, 23, 46), 987, "ms",     "23:45 – 23:46"},
2113             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 1, 23, 46), 987, "msS",    "23:45.3 – 23:46.9"},
2114             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 1, 23, 46), 987, "msSS",   "23:45.32 – 23:46.98"},
2115             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 1, 23, 46), 987, "msSSS",  "23:45.321 – 23:46.987"},
2116             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 2, 24, 45), 987, "ms",     "23:45 – 24:45"},
2117             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 2, 24, 45), 987, "msS",    "23:45.3 – 24:45.9"},
2118             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 2, 24, 45), 987, "msSS",   "23:45.32 – 24:45.98"},
2119             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 2, 24, 45), 987, "msSSS",  "23:45.321 – 24:45.987"},
2120             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 1, 23, 45), 321, "s",      "45"},
2121             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 1, 23, 45), 321, "sS",     "45.3"},
2122             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 1, 23, 45), 321, "sSS",    "45.32"},
2123             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 1, 23, 45), 321, "sSSS",   "45.321"},
2124             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 1, 23, 45), 987, "s",      "45"},
2125             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 1, 23, 45), 987, "sS",     "45.3 – 45.9"},
2126             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 1, 23, 45), 987, "sSS",    "45.32 – 45.98"},
2127             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 1, 23, 45), 987, "sSSS",   "45.321 – 45.987"},
2128             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 1, 23, 46), 987, "s",      "45 – 46"},
2129             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 1, 23, 46), 987, "sS",     "45.3 – 46.9"},
2130             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 1, 23, 46), 987, "sSS",    "45.32 – 46.98"},
2131             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 1, 23, 46), 987, "sSSS",   "45.321 – 46.987"},
2132             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 2, 24, 45), 987, "s",      "45 – 45"},
2133             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 2, 24, 45), 987, "sS",     "45.3 – 45.9"},
2134             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 2, 24, 45), 987, "sSS",    "45.32 – 45.98"},
2135             { new Date(2019, 2, 10, 1, 23, 45), 321, new Date(2019, 2, 10, 2, 24, 45), 987, "sSSS",   "45.321 – 45.987"},
2136         };
2137 
2138         Locale enLocale = Locale.ENGLISH;
2139 
2140         for (Object[] testCase : kTestCases) {
2141             DateIntervalFormat fmt = DateIntervalFormat.getInstance((String)testCase[4], enLocale);
2142 
2143             Date fromDate = (Date)testCase[0];
2144             long from = fromDate.getTime() + (Integer)testCase[1];
2145             Date toDate = (Date)testCase[2];
2146             long to = toDate.getTime() + (Integer)testCase[3];
2147 
2148             FormattedDateInterval res = fmt.formatToValue(new DateInterval(from, to));
2149             assertEquals("Formate for " + testCase[4], testCase[5], res.toString());
2150         }
2151     }
2152 }
2153