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
Fix Leica .lei timestamp formatting #1508
Conversation
Millisecond parsing in Joda has different results than with Date/SimpleDateFormat. If the number of ms digits in the format string exceeds the number of ms digits in the date string, then zero padding happens on the wrong side (e.g. 93 becomes 930 instead of 093). If the number of ms digits in the date string exceeds the number of ms digits in the format string, then parsing fails. See JodaOrg/joda-time#62. Fixes #12117.
return timestamp.getMillis(); | ||
SimpleDateFormat f = new SimpleDateFormat(format); | ||
Date d = f.parse(date, new ParsePosition(0)); | ||
if (d == null) return -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we want to continue to throw an IllegalArgumentException in this case as before, rather than returning -1, which is a valid-but-incorrect date? There's no way to distinguish between a valid date and an error condition. I should have clarified when writing this comment that this isn't a change in behaviour from this PR, but it should arguably not be returning an invalid date and just throw.
The change looks reasonable, but I'll have to do some testing to check how this behaves WRT timezones given that it's passing through Date. Ideally this should be resulting in a UTC timestamp, not offset to local time. |
An alternative solution would be to correct the input in LeicaReader:
(just as an example; the regex compiling should really be outside the loop) |
The change, bar the exception handling/error return comment above, looks OK. However, I'm not convinced this is necessarily the best solution. My main concern is that this removes the timezone support which joda provides, but which Date lacks, and which was the primary reason for replacing it with joda. The root problem is that the parsing of |
My 2¢:
@rleigh-dundee's suggestion of fixing up the strings before parsing them into timestamps is a good one, but unless we think that this idea that 01.44 is really 01.044 is fairly ubiquitous, I'd be leery of doing it in general code instead of lei-specific code. |
…estamps" This reverts commit 61db1c1.
Fixes #12117. Joda does not deal with variable-length millisecond values, so this parses the milliseconds separately.
Pushed two commits to revert the DateTools change and fix this in the Leica reader. I am concerned that we will run into the same problem elsewhere, so it will be important to keep an eye out for similar problems going forward. |
The change looks fine, thanks. The only minor detail is that with
Would it be possible to pad the millisecond formatting appropriately here, to remove the ambiguity? Or alternatively, use the normalised Timestamp value so it's a proper ISO-8601 date string. |
Should be sorted out now. |
The output is now fine, thanks. Do we need two assignments of |
One more commit pushed to address the last comment. Hopefully nothing further that needs to be fixed? |
The change looks fine, thanks. Good to merge if green from me. |
Fix Leica .lei timestamp formatting
--no-rebase |
Millisecond parsing in Joda has different results than with Date/SimpleDateFormat. If the number of ms digits in the format string exceeds the number of ms digits in the date string, then zero padding happens on the wrong side (e.g. 93 becomes 930 instead of 093). If the number of ms digits in the date string exceeds the number of ms digits in the format string, then parsing fails.
See JodaOrg/joda-time#62.
Fixes http://trac.openmicroscopy.org/ome/ticket/12117.