[threeten-dev] It looks ResolverStyle.LEINENT does not work as description in javadoc

Patrick Zhang patrick.zhang at oracle.com
Fri May 10 01:25:02 PDT 2013


Hi Team,

==================

public static finalResolverStyle  <http://sqeweb.us.oracle.com/jsn/users/patrick/threeten/build/linux-x86-normal-server-release/docs/api/java/time/format/ResolverStyle.html>  LENIENT

Style to resolve dates and times leniently.

Using lenient resolution will resolve the values in an appropriate 
lenient manner. Individual fields will interpret this differently.

For example, lenient mode allows the month in the ISO calendar system to 
be outside the range 1 to 12. For example, month 15 is treated as being 
3 months after month 12.
==================

My simple test code:
==================
                 DateTimeFormatterBuilder builder = new 
DateTimeFormatterBuilder();
                 DateTimeFormatter formatter1 = 
builder.appendValue(ChronoField.YEAR).appendLiteral("-")
                                                       
.appendValue(ChronoField.MONTH_OF_YEAR).appendLiteral("-")
                                                       
.appendValue(ChronoField.DAY_OF_MONTH)
                                                       .toFormatter();
//              formatter1.withResolverStyle(ResolverStyle.SMART);
//              System.out.println(formatter1.parse("2000-2-30"));

                 formatter1.withResolverStyle(ResolverStyle.LENIENT);
                 System.out.println(formatter1.parse("2000-15-30"));
==================
I expect eagerly it will print sth like "2001-03-30" or  "2000-03-30". :)
But it throws exception. Do I make any mistake here?

FYI, ResolverStyle.SMART will parse "2000-2-30" to "2000-02-29" correctly.

Regards
Patrick




More information about the threeten-dev mailing list