Skip to content

Commit

Permalink
Merge pull request #1508 from melissalinkert/12117
Browse files Browse the repository at this point in the history
Fix Leica .lei timestamp formatting
  • Loading branch information
melissalinkert committed Feb 18, 2015
2 parents 53939a7 + c2c40d4 commit 9cffb68
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions components/formats-gpl/src/loci/formats/in/LeicaReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class LeicaReader extends FormatReader {
private static final int LEICA_MAGIC_TAG = 33923;

/** Format for dates. */
private static final String DATE_FORMAT = "yyyy:MM:dd,HH:mm:ss:SSS";
private static final String DATE_FORMAT = "yyyy:MM:dd,HH:mm:ss";

/** IFD tags. */
private static final Integer SERIES = new Integer(10);
Expand Down Expand Up @@ -670,7 +670,7 @@ else if (getSizeT() > 1 && getImageCount() == getSizeC() * getSizeZ()) {
if (i < timestamps.length && timestamps[i] != null &&
timestamps[i].length > 0)
{
firstPlane = DateTools.getTime(timestamps[i][0], DATE_FORMAT);
firstPlane = getTime(timestamps[i][0]);
String date = DateTools.formatDate(timestamps[i][0], DATE_FORMAT);
if (date != null) {
store.setImageAcquisitionDate(new Timestamp(date), i);
Expand Down Expand Up @@ -735,7 +735,7 @@ else if (getSizeT() > 1 && getImageCount() == getSizeC() * getSizeZ()) {

for (int j=0; j<ms.imageCount; j++) {
if (timestamps[i] != null && j < timestamps[i].length) {
long time = DateTools.getTime(timestamps[i][j], DATE_FORMAT);
long time = getTime(timestamps[i][j]);
double elapsedTime = (double) (time - firstPlane) / 1000;
store.setPlaneDeltaT(new Time(elapsedTime, UNITS.S), i, j);
if (exposureTime[i] > 0) {
Expand Down Expand Up @@ -1152,7 +1152,8 @@ private void parseTimeTag(int seriesIndex) throws IOException {
addSeriesMeta("Number of time-stamps", numStamps);
timestamps[seriesIndex] = new String[numStamps];
for (int j=0; j<numStamps; j++) {
timestamps[seriesIndex][j] = getString(64);
timestamps[seriesIndex][j] = DateTools.convertDate(
getTime(getString(64)), DateTools.UNIX, DATE_FORMAT + ":SSS");
addSeriesMetaList("Timestamp", timestamps[seriesIndex][j]);
}

Expand Down Expand Up @@ -1672,6 +1673,13 @@ private static Hashtable<Integer, String> makeDimensionTable() {
return table;
}

private long getTime(String stamp) {
int msSeparator = stamp.lastIndexOf(":");
String newStamp = stamp.substring(0, msSeparator);
long ms = Long.parseLong(stamp.substring(msSeparator + 1));
return DateTools.getTime(newStamp, DATE_FORMAT) + ms;
}

// -- Helper class --

class Detector {
Expand Down

0 comments on commit 9cffb68

Please sign in to comment.