Skip to content

Commit

Permalink
Added functionality to parse HFS+ dates.
Browse files Browse the repository at this point in the history
  • Loading branch information
unsound committed Nov 4, 2006
1 parent ba58dec commit 79af432
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/FileSystemBrowserWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -444,15 +444,15 @@ public void populateTable(HFSPlusCatalogLeafRecord[] contents) {
currentRow.add(new RecordContainer(rec));
currentRow.add(catFile.getDataFork().getLogicalSize() + " B");
currentRow.add("File");
currentRow.add("" + catFile.getContentModDate());
currentRow.add("" + catFile.getContentModDateAsDate());
}
else if(recData.getRecordType() == HFSPlusCatalogLeafRecordData.RECORD_TYPE_FOLDER &&
recData instanceof HFSPlusCatalogFolder) {
HFSPlusCatalogFolder catFolder = (HFSPlusCatalogFolder)recData;
currentRow.add(new RecordContainer(rec));
currentRow.add("");
currentRow.add("Folder");
currentRow.add("" + catFolder.getContentModDate());
currentRow.add("" + catFolder.getContentModDateAsDate());
}
else if(recData.getRecordType() == HFSPlusCatalogLeafRecordData.RECORD_TYPE_FOLDER_THREAD &&
recData instanceof HFSPlusCatalogThread) {
Expand Down
17 changes: 12 additions & 5 deletions src/HFSPlusCatalogFile.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import java.io.PrintStream;
import java.util.Date;

/** This class was generated by CStructToJavaClass. */
public class HFSPlusCatalogFile extends HFSPlusCatalogLeafRecordData {
Expand Down Expand Up @@ -82,17 +83,23 @@ public HFSPlusCatalogFile(byte[] data, int offset) {
public HFSPlusForkData getDataFork() { return dataFork; }
public HFSPlusForkData getResourceFork() { return resourceFork; }

public Date getCreateDateAsDate() { return HFSPlusDate.toDate(getCreateDate()); }
public Date getContentModDateAsDate() { return HFSPlusDate.toDate(getContentModDate()); }
public Date getAttributeModDateAsDate() { return HFSPlusDate.toDate(getAttributeModDate()); }
public Date getAccessDateAsDate() { return HFSPlusDate.toDate(getAccessDate()); }
public Date getBackupDateAsDate() { return HFSPlusDate.toDate(getBackupDate()); }

public void printFields(PrintStream ps, String prefix) {
ps.println(prefix + " recordType: " + getRecordType());
ps.println(prefix + " flags: " + getFlags());
ps.println(prefix + " reserved1: " + getReserved1());
ps.println(prefix + " fileID: ");
getFileID().print(ps, prefix+" ");
ps.println(prefix + " createDate: " + getCreateDate());
ps.println(prefix + " contentModDate: " + getContentModDate());
ps.println(prefix + " attributeModDate: " + getAttributeModDate());
ps.println(prefix + " accessDate: " + getAccessDate());
ps.println(prefix + " backupDate: " + getBackupDate());
ps.println(prefix + " createDate: " + getCreateDateAsDate());
ps.println(prefix + " contentModDate: " + getContentModDateAsDate());
ps.println(prefix + " attributeModDate: " + getAttributeModDateAsDate());
ps.println(prefix + " accessDate: " + getAccessDateAsDate());
ps.println(prefix + " backupDate: " + getBackupDateAsDate());
ps.println(prefix + " permissions: ");
getPermissions().print(ps, prefix+" ");
ps.println(prefix + " userInfo: ");
Expand Down
17 changes: 12 additions & 5 deletions src/HFSPlusCatalogFolder.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import java.io.PrintStream;
import java.util.Date;

/** This class was generated by CStructToJavaClass. */
public class HFSPlusCatalogFolder extends HFSPlusCatalogLeafRecordData {
Expand Down Expand Up @@ -74,17 +75,23 @@ public HFSPlusCatalogFolder(byte[] data, int offset) {
public int getTextEncoding() { return Util.readIntBE(textEncoding); }
public int getReserved() { return Util.readIntBE(reserved); }

public Date getCreateDateAsDate() { return HFSPlusDate.toDate(getCreateDate()); }
public Date getContentModDateAsDate() { return HFSPlusDate.toDate(getContentModDate()); }
public Date getAttributeModDateAsDate() { return HFSPlusDate.toDate(getAttributeModDate()); }
public Date getAccessDateAsDate() { return HFSPlusDate.toDate(getAccessDate()); }
public Date getBackupDateAsDate() { return HFSPlusDate.toDate(getBackupDate()); }

public void printFields(PrintStream ps, String prefix) {
ps.println(prefix + " recordType: " + getRecordType());
ps.println(prefix + " flags: " + getFlags());
ps.println(prefix + " valence: " + getValence());
ps.println(prefix + " folderID: ");
getFolderID().print(ps, prefix+" ");
ps.println(prefix + " createDate: " + getCreateDate());
ps.println(prefix + " contentModDate: " + getContentModDate());
ps.println(prefix + " attributeModDate: " + getAttributeModDate());
ps.println(prefix + " accessDate: " + getAccessDate());
ps.println(prefix + " backupDate: " + getBackupDate());
ps.println(prefix + " createDate: " + getCreateDateAsDate());
ps.println(prefix + " contentModDate: " + getContentModDateAsDate());
ps.println(prefix + " attributeModDate: " + getAttributeModDateAsDate());
ps.println(prefix + " accessDate: " + getAccessDateAsDate());
ps.println(prefix + " backupDate: " + getBackupDateAsDate());
ps.println(prefix + " permissions: ");
getPermissions().print(ps, prefix+" ");
ps.println(prefix + " userInfo: ");
Expand Down
16 changes: 16 additions & 0 deletions src/HFSPlusDate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import java.util.Date;

/** In the future, this should wrap a 32 bit HFS+ date. */

public class HFSPlusDate {
/**
* Pre-calculated. This is the amount of milliseconds between 01-01-1904 00:00:00.0000
* (HFS+ starting date) and 01-01-1970 00:00:00.0000 (the start of the java "epoch").
*/
public static final long DIFF_TO_JAVA_DATE_IN_MILLIS = 2082844800000L;

/** Converts a HFS+ date to a Java Date. */
public static Date toDate(int hfsPlusTimestamp) {
return new Date(Util2.unsign(hfsPlusTimestamp)*1000 - DIFF_TO_JAVA_DATE_IN_MILLIS);
}
}

0 comments on commit 79af432

Please sign in to comment.