Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/text/Format/DateFormat/bug4358730.java
46973 views
/*1* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.io.*;24import java.util.*;25import java.text.*;2627/**28* @test29* @bug 435873030* @library /java/text/testlib31* @summary test that confirms Zero-Padding on year.32*/3334public class bug4358730 extends IntlTest {3536public static void main(String[] args) throws Exception {37new bug4358730().run(args);38}3940String[] patterns = {"y", "yy", "yyy", "yyyy", "yyyyy"};41String[][] data = {42/* 2 A.D. */ {"2", "02", "002", "0002", "00002"},43/* 20 A.D. */ {"20", "20", "020", "0020", "00020"},44/* 200 A.D. */ {"200", "00", "200", "0200", "00200"},45/* 2000 A.D. */ {"2000", "00", "2000", "2000", "02000"},46};47int[] year = {2, 20, 200, 2000};4849SimpleDateFormat sdf = new SimpleDateFormat();50int datasize = data.length;51int nPatterns = data[0].length;5253public void Test4358730() {54Locale locale = Locale.getDefault();55if (locale.equals(new Locale("th", "TH")) ||56locale.equals(new Locale("hi", "IN"))) {57return;58}5960TimeZone saveZone = TimeZone.getDefault();61Locale saveLocale = Locale.getDefault();6263try {64TimeZone.setDefault(TimeZone.getTimeZone("PST"));65Locale.setDefault(new Locale("en", "US"));6667for (int i = 0; i < datasize; i++) {68Date d = new Date(year[i]-1900, 10, 15);69for (int j = 0; j < nPatterns; j++) {70sdf.applyPattern(patterns[j]);71if (!data[i][j].equals(sdf.format(d))) {72errln("Invalid format : " + sdf.format(d) +73", expected : " + data[i][j]);74}75}76}77}78finally {79TimeZone.setDefault(saveZone);80Locale.setDefault(saveLocale);81}82}83}848586