1

It would seem to me that the following Groovy Script should fail with parsing exceptions:

println Date.parse("yyyy-MM-dd'T'HH:mm:ss","2014-10-06T05:58:00-0500")
println Date.parse("yyyy-MM-dd'T'HH:mm:ss","2014-14-06T05:58:00-0500")
println Date.parse("yyyy-MM-dd'T'HH:mm:ss","2014-10-45T05:58:00-0500")
println Date.parse("yyyy-MM-dd'T'HH:mm:ss","2014-10-06T35:58:00-0500")
println Date.parse("yyyy-MM-dd'T'HH:mm:ss","2014-10-06T05:95:00-0500")

Note that:

  • the second date has an invalid month
  • the third date has an invalid day
  • the fourth date has an invalid hour
  • the fifth date has invalid minutes

I'm pretty sure that I know what it is actually doing, but it is not what I expect to happen.

George Smith
  • 1,027
  • 4
  • 11
  • 23

1 Answers1

0

As written in the docs parse is just a wrapper around SimpleDateFormat. It is possible to unset SimpleDateFormat lenient as in this answer however I suppose it's not possible to it when invoking just Date.parse. So to get correct results You should use a strict SimpleDateFormat.

Community
  • 1
  • 1
Opal
  • 81,889
  • 28
  • 189
  • 210