42 import java.time.format.DecimalStyle; |
43 import java.time.format.DecimalStyle; |
43 import java.time.format.DateTimeFormatter; |
44 import java.time.format.DateTimeFormatter; |
44 import java.time.format.DateTimeFormatterBuilder; |
45 import java.time.format.DateTimeFormatterBuilder; |
45 import java.time.format.DateTimeParseException; |
46 import java.time.format.DateTimeParseException; |
46 import java.time.format.FormatStyle; |
47 import java.time.format.FormatStyle; |
|
48 import java.time.format.ResolverStyle; |
47 import java.time.format.TextStyle; |
49 import java.time.format.TextStyle; |
48 import java.time.temporal.TemporalAccessor; |
50 import java.time.temporal.TemporalAccessor; |
49 import java.time.temporal.TemporalQueries; |
51 import java.time.temporal.TemporalQueries; |
50 import java.util.Locale; |
52 import java.util.Locale; |
51 |
53 |
133 + "\u0627\u0644\u0625\u0633\u0644\u0627\u0645\u064a " |
135 + "\u0627\u0644\u0625\u0633\u0644\u0627\u0645\u064a " |
134 + "(\u0623\u0645 \u0627\u0644\u0642\u0631\u0649)" }, |
136 + "(\u0623\u0645 \u0627\u0644\u0642\u0631\u0649)" }, |
135 }; |
137 }; |
136 } |
138 } |
137 |
139 |
|
140 @DataProvider(name="lenient_eraYear") |
|
141 Object[][] lenientEraYear() { |
|
142 return new Object[][] { |
|
143 // Chronology, lenient era/year, strict era/year |
|
144 { JAPANESE, "Meiji 123", "Heisei 2" }, |
|
145 { JAPANESE, "Showa 65", "Heisei 2" }, |
|
146 { JAPANESE, "Heisei 32", "NewEra 2" }, // NewEra |
|
147 }; |
|
148 } |
|
149 |
138 @Test(dataProvider="format_data") |
150 @Test(dataProvider="format_data") |
139 public void test_formatLocalizedDate(Chronology chrono, Locale formatLocale, Locale numberingLocale, |
151 public void test_formatLocalizedDate(Chronology chrono, Locale formatLocale, Locale numberingLocale, |
140 ChronoLocalDate date, String expected) { |
152 ChronoLocalDate date, String expected) { |
141 DateTimeFormatter dtf = DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL) |
153 DateTimeFormatter dtf = DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL) |
142 .withChronology(chrono).withLocale(formatLocale) |
154 .withChronology(chrono).withLocale(formatLocale) |
171 assertEquals(text, expected); |
183 assertEquals(text, expected); |
172 TemporalAccessor ta = dtf.parse(text); |
184 TemporalAccessor ta = dtf.parse(text); |
173 Chronology cal = ta.query(TemporalQueries.chronology()); |
185 Chronology cal = ta.query(TemporalQueries.chronology()); |
174 assertEquals(cal, chrono); |
186 assertEquals(cal, chrono); |
175 } |
187 } |
|
188 |
|
189 @Test(dataProvider="lenient_eraYear") |
|
190 public void test_lenientEraYear(Chronology chrono, String lenient, String strict) { |
|
191 String mdStr = "-01-01"; |
|
192 DateTimeFormatter dtf = new DateTimeFormatterBuilder() |
|
193 .appendPattern("GGGG y-M-d") |
|
194 .toFormatter() |
|
195 .withChronology(chrono); |
|
196 DateTimeFormatter dtfLenient = dtf.withResolverStyle(ResolverStyle.LENIENT); |
|
197 assertEquals(LocalDate.parse(lenient+mdStr, dtfLenient), LocalDate.parse(strict+mdStr, dtf)); |
|
198 } |
176 } |
199 } |