8246623: Remove minimum 4 digit requirement from Year.parse()

Reviewed-by: lancea, rriggs, joehw
This commit is contained in:
Naoto Sato 2020-06-15 09:21:39 -07:00
parent 38f9a938e5
commit 23e2f27996
2 changed files with 35 additions and 15 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012, 2019, 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -153,7 +153,8 @@ public final class Year
* Parser. * Parser.
*/ */
private static final DateTimeFormatter PARSER = new DateTimeFormatterBuilder() private static final DateTimeFormatter PARSER = new DateTimeFormatterBuilder()
.appendValue(YEAR, 4, 10, SignStyle.EXCEEDS_PAD) .parseLenient()
.appendValue(YEAR, 1, 10, SignStyle.NORMAL)
.toFormatter(); .toFormatter();
/** /**
@ -268,7 +269,6 @@ public final class Year
* Obtains an instance of {@code Year} from a text string such as {@code 2007}. * Obtains an instance of {@code Year} from a text string such as {@code 2007}.
* <p> * <p>
* The string must represent a valid year. * The string must represent a valid year.
* Years outside the range 0000 to 9999 must be prefixed by the plus or minus symbol.
* *
* @param text the text to parse such as "2007", not null * @param text the text to parse such as "2007", not null
* @return the parsed year, not null * @return the parsed year, not null

View file

@ -1,5 +1,5 @@
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -248,10 +248,32 @@ public class TCKYear extends AbstractDateTimeTest {
@DataProvider(name="goodParseData") @DataProvider(name="goodParseData")
Object[][] provider_goodParseData() { Object[][] provider_goodParseData() {
return new Object[][] { return new Object[][] {
{"0000", Year.of(0)},
{"9999", Year.of(9999)}, {"9999", Year.of(9999)},
{"2000", Year.of(2000)}, {"2000", Year.of(2000)},
{"0", Year.of(0)},
{"00", Year.of(0)},
{"000", Year.of(0)},
{"0000", Year.of(0)},
{"00000", Year.of(0)},
{"+00000", Year.of(0)},
{"-0", Year.of(0)},
{"-00", Year.of(0)},
{"-000", Year.of(0)},
{"-0000", Year.of(0)},
{"-00000", Year.of(0)},
{"1", Year.of(1)},
{"01", Year.of(1)},
{"001", Year.of(1)},
{"0001", Year.of(1)},
{"00001", Year.of(1)},
{"+00001", Year.of(1)},
{"-1", Year.of(-1)},
{"-01", Year.of(-1)},
{"-001", Year.of(-1)},
{"-0001", Year.of(-1)},
{"-00001", Year.of(-1)},
{"+12345678", Year.of(12345678)}, {"+12345678", Year.of(12345678)},
{"+123456", Year.of(123456)}, {"+123456", Year.of(123456)},
{"-1234", Year.of(-1234)}, {"-1234", Year.of(-1234)},
@ -272,20 +294,18 @@ public class TCKYear extends AbstractDateTimeTest {
Object[][] provider_badParseData() { Object[][] provider_badParseData() {
return new Object[][] { return new Object[][] {
{"", 0}, {"", 0},
{"-00", 1},
{"--01-0", 1}, {"--01-0", 1},
{"A01", 0}, {"A01", 0},
{"200", 0},
{"2009/12", 4}, {"2009/12", 4},
{"-0000-10", 0}, {"-0000-10", 5},
{"-12345678901-10", 11}, {"-12345678901-10", 10},
{"+1-10", 1}, {"+1-10", 2},
{"+12-10", 1}, {"+12-10", 3},
{"+123-10", 1}, {"+123-10", 4},
{"+1234-10", 0}, {"+1234-10", 5},
{"12345-10", 0}, {"12345-10", 5},
{"+12345678901-10", 11}, {"+12345678901-10", 10},
}; };
} }