Changeset 2960 for trunk


Ignore:
Timestamp:
07/10/07 15:01:16 (13 years ago)
Author:
melissa
Message:

Converted HighInteger/LowInteger fields to real timestamp.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/formats/in/LIFReader.java

    r2922 r2960  
    2727import java.awt.image.BufferedImage; 
    2828import java.io.*; 
     29import java.text.*; 
    2930import java.util.*; 
    3031import javax.xml.parsers.*; 
     
    633634      } 
    634635      else if (qName.equals("TimeStamp")) { 
    635         String prefix = series + " - TimeStamp " + count + " - "; 
    636         addMeta(prefix + "HighInteger", attributes.getValue("HighInteger")); 
    637         addMeta(prefix + "LowInteger", attributes.getValue("LowInteger")); 
     636        
     637        long high = Long.parseLong(attributes.getValue("HighInteger")); 
     638        long low = Long.parseLong(attributes.getValue("LowInteger")); 
     639  
     640        long stamp = 0; 
     641        high <<= 32; 
     642        if ((int) low < 0) { 
     643          low &= 0xffffffffL; 
     644        } 
     645        stamp = high + low; 
     646         
     647        // Near as I can figure, this timestamp represents the number of  
     648        // 100-nanosecond ticks since the ANSI/COBOL epoch (Jan 1, 1601). 
     649        // Note that the following logic does not handle negative timestamp 
     650        // values, so if the file in question was acquired prior to Jan 1 1601, 
     651        // the timestamp will not be parsed correctly. 
     652         
     653        long seconds = stamp / 10000000;  
     654 
     655        // subtract number of seconds until Unix epoch (Jan 1, 1970) 
     656 
     657        long secondsPerYear = (long) (60 * 60 * 24 * 365.25); 
     658        seconds -= secondsPerYear * (1970 - 1601);  
     659        
     660        Date d = new Date(seconds * 1000);  
     661        SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); 
     662        StringBuffer sb = new StringBuffer(); 
     663        fmt.format(d, sb, new FieldPosition(0)); 
     664        addMeta(series + " - TimeStamp " + count, sb.toString()); 
     665 
    638666        count++; 
    639667      } 
Note: See TracChangeset for help on using the changeset viewer.