Skip to main content

Correctness

My first point is that the current date is accepted as a valid future daedate. That is odd, and it is certainly not according to :

Tests whether the date input represents a real date in mm/dd/YYYY format that is after the current date.

Simplicity

Secondly, assuming the current date should return false, the entire implementation can be as simple as :

public static boolean isValidDate(String pDateString) throws ParseException {
        Date date = new SimpleDateFormat("MM/dd/yyyy").parse(pDateString);
        return new Date().before(date);
}

Testable

Lastly, this method is difficult to test. Does it work when now falls in a DST overlap period? Does it work on 29th of februariFebruary? Does it work in the time zone "Australia/Darwin""Australia/Darwin"?

While you may not use Java 8Java 8, you can certainly make a Clock abstraction of your own to get around this.

Correctness

My first point is that the current date is accepted as a valid future dae. That is odd, and it is certainly not according to :

Tests whether the date input represents a real date in mm/dd/YYYY format that is after the current date.

Simplicity

Secondly, assuming the current date should return false, the entire implementation can be as simple as :

public static boolean isValidDate(String pDateString) throws ParseException {
        Date date = new SimpleDateFormat("MM/dd/yyyy").parse(pDateString);
        return new Date().before(date);
}

Testable

Lastly, this method is difficult to test. Does it work when now falls in a DST overlap period? Does it work on 29th of februari? Does it work in the time zone "Australia/Darwin"?

While you may not use Java 8, you can certainly make a Clock abstraction of your own to get around this.

Correctness

My first point is that the current date is accepted as a valid future date. That is odd, and it is certainly not according to :

Tests whether the date input represents a real date in mm/dd/YYYY format that is after the current date.

Simplicity

Secondly, assuming the current date should return false, the entire implementation can be as simple as :

public static boolean isValidDate(String pDateString) throws ParseException {
        Date date = new SimpleDateFormat("MM/dd/yyyy").parse(pDateString);
        return new Date().before(date);
}

Testable

Lastly, this method is difficult to test. Does it work when now falls in a DST overlap period? Does it work on 29th of February? Does it work in the time zone "Australia/Darwin"?

While you may not use Java 8, you can certainly make a Clock abstraction of your own to get around this.

Source Link
bowmore
  • 5.4k
  • 1
  • 20
  • 23

Correctness

My first point is that the current date is accepted as a valid future dae. That is odd, and it is certainly not according to :

Tests whether the date input represents a real date in mm/dd/YYYY format that is after the current date.

Simplicity

Secondly, assuming the current date should return false, the entire implementation can be as simple as :

public static boolean isValidDate(String pDateString) throws ParseException {
        Date date = new SimpleDateFormat("MM/dd/yyyy").parse(pDateString);
        return new Date().before(date);
}

Testable

Lastly, this method is difficult to test. Does it work when now falls in a DST overlap period? Does it work on 29th of februari? Does it work in the time zone "Australia/Darwin"?

While you may not use Java 8, you can certainly make a Clock abstraction of your own to get around this.