< prev index next >
test/jdk/java/time/tck/java/time/format/TCKLocalizedPrinterParser.java
Print this page
8247706: Unintentional use of new Date(year...) with absolute year
Reviewed-by: naoto, rriggs, scolebourne
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
@@ -178,11 +178,11 @@
@SuppressWarnings("deprecation")
@Test(dataProvider="time")
public void test_time_print(LocalTime time, FormatStyle timeStyle, int timeStyleOld, Locale locale) {
DateFormat old = DateFormat.getTimeInstance(timeStyleOld, locale);
- Date oldDate = new Date(1970, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
+ Date oldDate = new Date(1970 - 1900, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
String text = old.format(oldDate);
DateTimeFormatter f = builder.appendLocalized(null, timeStyle).toFormatter(locale);
String formatted = f.format(time);
assertEquals(formatted, text);
@@ -190,11 +190,11 @@
@SuppressWarnings("deprecation")
@Test(dataProvider="time")
public void test_time_parse(LocalTime time, FormatStyle timeStyle, int timeStyleOld, Locale locale) {
DateFormat old = DateFormat.getTimeInstance(timeStyleOld, locale);
- Date oldDate = new Date(1970, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
+ Date oldDate = new Date(1970 - 1900, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
String text = old.format(oldDate);
DateTimeFormatter f = builder.appendLocalized(null, timeStyle).toFormatter(locale);
TemporalAccessor parsed = f.parse(text, pos);
assertEquals(pos.getIndex(), text.length());
< prev index next >