< prev index next >

test/jdk/java/util/Calendar/ZoneOffsets.java

Print this page
rev 54350 : 8205432: Replace the placeholder Japanese era name
Reviewed-by: rriggs
   1 /*
   2  * Copyright (c) 2005, 2018, 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  */


 223         cal2.setTimeZone(tz3);
 224         cal2.clear();
 225         cal2.set(2005, MARCH, 11);
 226         adjustJapaneseEra(cal2);
 227         // test8: set both ZONE_OFFSET and DST_OFFSET in non-lenient
 228         cal2.set(ZONE_OFFSET, gmtOffset);
 229         cal2.set(DST_OFFSET, dstOffset);
 230         if (t1 != cal2.getTime().getTime()) {
 231             error("Test8", loc, cal2, gmtOffset, dstOffset, t1);
 232         }
 233     }
 234 
 235     private static void error(String msg, Locale loc, Calendar cal2, int gmtOffset, int dstOffset, long t1) {
 236         System.err.println(cal2);
 237         throw new RuntimeException(msg + ": Locale=" + loc
 238                 + ", gmtOffset=" + gmtOffset + ", dstOffset=" + dstOffset
 239                 + ", cal1 time=" + t1 + ", cal2 time=" + cal2.getTime().getTime());
 240     }
 241 
 242     private static void adjustJapaneseEra(Calendar cal) {
 243         // In case of Japanese calendar, explicitly set the last era; NEWERA so that
 244         // year 2005 won't throw exception
 245         if (!cal.isLenient() &&
 246                 cal.getCalendarType().equals("japanese") &&
 247                 System.currentTimeMillis() < 1556668800000L) { // Current time not in NEWERA
 248             cal.set(Calendar.ERA, 5);
 249             cal.add(Calendar.YEAR, -30); // -30: Subtract year-length of HEISEI era
 250         }
 251         return;
 252     }
 253 }
   1 /*
   2  * Copyright (c) 2005, 2019, 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  */


 223         cal2.setTimeZone(tz3);
 224         cal2.clear();
 225         cal2.set(2005, MARCH, 11);
 226         adjustJapaneseEra(cal2);
 227         // test8: set both ZONE_OFFSET and DST_OFFSET in non-lenient
 228         cal2.set(ZONE_OFFSET, gmtOffset);
 229         cal2.set(DST_OFFSET, dstOffset);
 230         if (t1 != cal2.getTime().getTime()) {
 231             error("Test8", loc, cal2, gmtOffset, dstOffset, t1);
 232         }
 233     }
 234 
 235     private static void error(String msg, Locale loc, Calendar cal2, int gmtOffset, int dstOffset, long t1) {
 236         System.err.println(cal2);
 237         throw new RuntimeException(msg + ": Locale=" + loc
 238                 + ", gmtOffset=" + gmtOffset + ", dstOffset=" + dstOffset
 239                 + ", cal1 time=" + t1 + ", cal2 time=" + cal2.getTime().getTime());
 240     }
 241 
 242     private static void adjustJapaneseEra(Calendar cal) {
 243         // In case of Japanese calendar, explicitly set the last era; REIWA so that
 244         // year 2005 won't throw exception
 245         if (!cal.isLenient() &&
 246                 cal.getCalendarType().equals("japanese") &&
 247                 System.currentTimeMillis() < 1556668800000L) { // Current time not in REIWA
 248             cal.set(Calendar.ERA, 5);
 249             cal.add(Calendar.YEAR, -30); // -30: Subtract year-length of HEISEI era
 250         }
 251         return;
 252     }
 253 }
< prev index next >