tinkerwell / jodd

Automatically exported from code.google.com/p/jodd
0 stars 0 forks source link

JDateTime should improve format process #30

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
first,my time pattern is like this(YYYYMMDDhhmmssmss) -- in jdt way.
then I use such pattern to format date created as follows:
 String timePattern = "YYYYMMDDhhmmssmss";

 JDateTime jdt = new JDateTime ();

 jdt.setDateTime(new Date());

 String format =  jdt.toString(timePattern);

but when I try to parse the "format" result above like this

 JDateTime jdt1 = new JDateTime ();

 jdt1.parse(format,timePattern);

 Date date = jdt1.convertToDate();

it throws the exception like this:
Exception in thread "main" java.lang.NumberFormatException: For input string: 
"20121005211409546"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
    at java.lang.Integer.parseInt(Integer.java:461)
    at java.lang.Integer.parseInt(Integer.java:499)
    at jodd.datetime.format.Iso8601JdtFormatter.parseValue(Iso8601JdtFormatter.java:130)
    at jodd.datetime.format.AbstractFormatter.parse(AbstractFormatter.java:189)
    at jodd.datetime.JDateTime.parse(JDateTime.java:1447)

What is the expected output? What do you see instead?
it should return the date I created ever before but the JDateTime throw
the exception

What version of the product are you using? On what operating system?
jodd3.8

Please provide any additional information below.

Original issue reported on code.google.com by jerrysco...@gmail.com on 5 Oct 2012 at 1:31

GoogleCodeExporter commented 9 years ago
Thank you for submitting the issue!

Agree, this should be better. Please let me explain why the exception happens. 
We wanted users to have freedom to specify fields larger then usual limits; for 
example to be able to specify year > 9999; or to specify month > 12 (e.g. 13 
months = 1 year + 1 month).

Therefore, the current parsing process requires some separators in order to 
work properly.

But you are right, your use case should work too!!! Therefore, we will add 
logic to detect when input has no separators (just numbers given); to parse it 
using exact given pattern.

I hope this make sense:)

Original comment by i...@jodd.org on 5 Oct 2012 at 1:54

GoogleCodeExporter commented 9 years ago
Fixed by
https://github.com/oblac/jodd/commit/d91a375a12f7828c825e45b7e8f4c71eb857f356

Deployed snapshots and uploaded new Jodd jars on site.

Original comment by i...@jodd.org on 5 Oct 2012 at 8:53

GoogleCodeExporter commented 9 years ago
Thanks for quick response and make it fixed as soon as possible. I will try to 
use the snapshot jar for test and I wonder when the final edition of jodd3.9 to 
be released.

Original comment by jerrysco...@gmail.com on 7 Oct 2012 at 2:07

GoogleCodeExporter commented 9 years ago
sorry it should be jodd3.4

Original comment by jerrysco...@gmail.com on 7 Oct 2012 at 2:07

GoogleCodeExporter commented 9 years ago
It is scheduled for October. There have been many organization changes in 3.4.0 
(new project structure) and we want to be careful before we release.

Original comment by i...@jodd.org on 7 Oct 2012 at 8:05