package tdl.record.sourcecode;

import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.text.MessageFormat;
import org.apache.commons.codec.binary.Hex;
import tdl.record.sourcecode.snapshot.KeySnapshot;
import tdl.record.sourcecode.snapshot.file.SnapshotFileSegment;
import tdl.record.sourcecode.snapshot.file.SnapshotsFileReader;

@Parameters(commandDescription = "List snapshots in the file.")
public class ListCommand extends Command {

    @Parameter(names = {"-i", "--input"}, description = "The SRCS input file.", required = true)
    private String inputFilePath;

    @Override
    public void run() {
        File file = Paths.get(inputFilePath).toFile();
        try (SnapshotsFileReader reader = new SnapshotsFileReader(file)) {
            int index = 0;
            while (reader.hasNext()) {
                SnapshotFileSegment segment = reader.next();
                printSnapshot(segment, index);
                index++;
            }
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }

    private static void printSnapshot(SnapshotFileSegment segment, int index) {
        String type = segment.getSnapshot() instanceof KeySnapshot ? "KEY" : "PATCH";
        long size = segment.size + SnapshotFileSegment.HEADER_SIZE;
        String checksum = Hex.encodeHexString(segment.checksum);

        String infoLine = String.format("#%4d | time %4s | type %-5s | offset %5d | size %5d | checksum %40s",
                index, segment.timestamp, type, segment.address, size, checksum);
        System.out.println(infoLine);

    }
}

@@ -213,16 +213,39 @@
 Format;%0A
+import java.util.Date;%0A
 import o
@@ -280,16 +280,16 @@
 ry.Hex;%0A
-
 import t
@@ -864,24 +864,98 @@
 er(file)) %7B%0A
+            Date start = new Date(reader.getFileHeader().getTimestamp());%0A
             
@@ -1113,16 +1113,23 @@
 t, index
+, start
 );%0A     
@@ -1274,15 +1274,8 @@
 ate 
-static 
 void
@@ -1327,16 +1327,28 @@
 nt index
+, Date start
 ) %7B%0A    
@@ -1562,16 +1562,101 @@
 cksum);%0A
+        String recorded = (new Date(start.getTime() + segment.timestamp)).toString();
 %0A       
@@ -1695,16 +1695,32 @@
 (%22#%254d %7C
+ recorded %2540s %7C
  time %254
@@ -1797,16 +1797,26 @@
   index,
+ recorded,
  segment
@@ -1905,17 +1905,16 @@
 oLine);%0A
-%0A
     %7D%0A%7D%0A

Add start date to list command