1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 8139572 27 * @summary SimpleDateFormat parse month stand-alone format bug 28 * @compile -encoding utf-8 Bug8139572.java 29 * @run main Bug8139572 30 */ 31 import java.text.ParseException; 32 import java.text.SimpleDateFormat; 33 import java.util.Calendar; 34 import java.util.Date; 35 import java.util.GregorianCalendar; 36 import java.util.Locale; 37 38 public class Bug8139572 { 39 40 private static final Locale RUSSIAN = new Locale("ru"); 41 private static final Date SEPT12 = new GregorianCalendar(2015, Calendar.SEPTEMBER, 12).getTime(); 42 43 private static final String[] PATTERNS = { 44 "L", 45 "dd L", 46 "dd L yy", 47 "dd L yyyy", 48 "LL", 49 "dd LL", 50 "dd LL yy", 51 "dd LL yyyy", 52 "LLL", 53 "dd LLL", 54 "dd LLL yy", 55 "dd LLL yyyy", 56 "LLLL", 57 "dd LLLL", 58 "dd LLLL yy", 59 "dd LLLL yyyy" 60 }; 61 62 private static final String[] APPLIED = { 63 "9", 64 "12 09", 65 "12 09 15", 66 "12 09 2015", 67 "09", 68 "12 09", 69 "12 09 15", 70 "12 09 2015", 71 "сентября", 72 "12 сентября", 73 "12 сентября 15", 74 "12 сентября 2015", 75 "сентября", 76 "12 сентября", 77 "12 сентября 15", 78 "12 сентября 2015" 79 }; 80 81 private static final String[] EXPECTED = { 82 "9", 83 "12 9", 84 "12 9 15", 85 "12 9 2015", 86 "09", 87 "12 09", 88 "12 09 15", 89 "12 09 2015", 90 "сент.", 91 "12 сент.", 92 "12 сент. 15", 93 "12 сент. 2015", 94 "сентябрь", 95 "12 сентябрь", 96 "12 сентябрь 15", 97 "12 сентябрь 2015" 98 }; 99 100 public static void main(String[] args) throws ParseException { 101 102 for (int i = 0; i < PATTERNS.length; i++) { 103 SimpleDateFormat fmt = new SimpleDateFormat(PATTERNS[i], RUSSIAN); 104 Date standAloneDate = fmt.parse(APPLIED[i]); 105 String str = fmt.format(standAloneDate); 106 if (!EXPECTED[i].equals(str)) { 107 throw new RuntimeException("bad result: got '" + str + "', expected '" + EXPECTED[i] + "'"); 108 } 109 } 110 111 SimpleDateFormat fmt = new SimpleDateFormat("", RUSSIAN); 112 for (int j = 0; j < PATTERNS.length; j++) { 113 fmt.applyPattern(PATTERNS[j]); 114 String str = fmt.format(SEPT12); 115 if (!EXPECTED[j].equals(str)) { 116 throw new RuntimeException("bad result: got '" + str + "', expected '" + EXPECTED[j] + "'"); 117 } 118 } 119 } 120 }