-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
StdDateFormat does not interpret "millis" correctly #1668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You are right, and this was my understanding as well (that one can only vary precision of second fraction, and if so, it would be interpreted the way you describe). So, flawed handling. Question then is whether this is something I'll see if I can quickly reproduce this now. |
Ok, I think this piece of code in // And possible also millisecond part if missing
if (timeLen < 12) { // missing, or partial
StringBuilder sb = new StringBuilder(dateStr);
switch (timeLen) {
case 11: sb.append('0');
case 10: sb.append('0');
case 9: sb.append('0');
break;
default:
sb.append(".000");
}
dateStr = sb.toString();
} with the obvious problem being wrong ordering (should add three zeroes if length I don't know is |
Fixed via #1678. Some notes:
|
Here is an excerpt from the ISO8601 norm (https://en.wikipedia.org/wiki/ISO_8601 - sorry could not find any official source) - in the Times section it says:
So the following representation are accepted:
01.5
, means 1 hour and a half, i.e. equivalent to01:30:00
01:01.5
, means 1 hour, 1 minute and a half, i.e. equivalent to01:01:30
01:01:01.5
, means ..., i.e. equivalent to01:01:01.500
It is important to note the norm doesn't have the concept of millis but fraction of seconds. This is even better explained by the BNF presented in RFC3339 (https://www.ietf.org/rfc/rfc3339.txt), section 5.6 and/or appendix A.
Unfortunately, the way Jackson's StdDateFormat treats the fraction of seconds is not inline with the above.
00:00:00.5
is interpreted as00:00:00.005
, i.e. 5 millis instead of 0.5 seconds.00:00:00.1234
is interpreted as00:00:01.234
, i.e. 1234 millis which is equivalent to 1 sec and 234 millis.These cases silently produce wrong date values - at least according to ISO8601 norm.
One can argue
java.util.Date
as millis precision only and won't be able to cope with.1234
anyway. This is true, but not a reason to produces wrong result. It should either truncate to the first 3 digits (as does Joda) or refuse and throw an InvalidFormatException.Issue described as of Jackson 2.8.9
The text was updated successfully, but these errors were encountered: