* support {age} for FileFilter expressions

This commit is contained in:
Reinhard Pointner 2015-07-25 22:47:00 +00:00
parent 6c22b3e502
commit a43a9171c1
3 changed files with 22 additions and 6 deletions

View File

@ -331,13 +331,17 @@ public class ExpressionFormatMethods {
return 0;
}
public static long getCreationDate(File self) throws IOException {
BasicFileAttributes attr = Files.getFileAttributeView(self.toPath(), BasicFileAttributeView.class).readAttributes();
long creationDate = attr.creationTime().toMillis();
if (creationDate > 0) {
return creationDate;
public static long getCreationDate(File self) {
try {
BasicFileAttributes attr = Files.getFileAttributeView(self.toPath(), BasicFileAttributeView.class).readAttributes();
long creationDate = attr.creationTime().toMillis();
if (creationDate > 0) {
return creationDate;
}
return attr.lastModifiedTime().toMillis();
} catch (IOException e) {
throw new RuntimeException(e);
}
return attr.lastModifiedTime().toMillis();
}
public static File toFile(String self) {

View File

@ -171,6 +171,9 @@ public class MediaBindingBean {
if (infoObject instanceof AudioTrack) {
return getMusic().getAlbumReleaseDate();
}
if (infoObject instanceof File) {
return new SimpleDate(getCreationDate(((File) infoObject)));
}
// no date info for the model
return null;

View File

@ -7,6 +7,7 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
@ -26,6 +27,14 @@ public class SimpleDate implements Serializable, Comparable<Object> {
this.day = day;
}
public SimpleDate(long t) {
GregorianCalendar c = new GregorianCalendar();
c.setTime(new Date(t));
year = c.get(Calendar.YEAR);
month = c.get(Calendar.MONTH) + 1;
day = c.get(Calendar.DAY_OF_MONTH);
}
public int getYear() {
return year;
}