Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use of "lenient "?

Here lenient is used in Java DateFormat. I checked the doc, but didn't get what it was saying.

Can any body please tell me what is the use of this lenient, with one real time example where we use it?

like image 606
Binaya Avatar asked Sep 30 '11 05:09

Binaya


People also ask

What is a lenient used for?

Today, lenient is most often used to describe a person or punishment as being soft or mild. The word is often used in the context of expressing that someone or something is either too lenient or not lenient enough.

What is meaning by lenient?

-nyənt. : of mild and tolerant disposition or effect : not harsh, severe, or strict. lenient laws. a lenient attitude. : exerting a soothing or easing influence : relieving pain or stress.

What is an example of lenient?

The definition of lenient is someone who is not strict or a punishment that is not severe. An example of something that would be described as lenient is a jail sentence of one day for armed robbery. Not harsh or strict; merciful or generous.


2 Answers

The javadoc clearly states:

Specify whether or not date/time parsing is to be lenient. With lenient parsing, the parser may use heuristics to interpret inputs that do not precisely match this object's format. With strict parsing, inputs must match this object's format.

So, if you have a pattern and create a date object that strictly matches your pattern, set lenient to false. Also, DateFormat is lenient, by default.

Basically, DateFormat sets Calendar.setLenient and the Javadoc states:

Specifies whether or not date/time interpretation is to be lenient. With lenient interpretation, a date such as "February 942, 1996" will be treated as being equivalent to the 941st day after February 1, 1996. With strict (non-lenient) interpretation, such dates will cause an exception to be thrown. The default is lenient.

like image 73
Buhake Sindi Avatar answered Sep 24 '22 08:09

Buhake Sindi


For example this:

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy"); System.out.println(simpleDateFormat.parse("0")); simpleDateFormat.setLenient(false); System.out.println(simpleDateFormat.parse("0")); 

results in:

Thu Jan 01 00:00:00 CET 1 Exception in thread "main" java.text.ParseException: Unparseable date: "0"     at java.text.DateFormat.parse(Unknown Source)     at net.java.quickcheck.generator.support.X.main(X.java:28) 
like image 22
Thomas Jung Avatar answered Sep 24 '22 08:09

Thomas Jung