Refactor Date {now} to SimpleDate {today}

This commit is contained in:
Reinhard Pointner 2016-08-09 23:46:03 +08:00
parent 3ed3f92b48
commit bddf3e516b
2 changed files with 21 additions and 12 deletions

View File

@ -22,8 +22,10 @@ import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -575,8 +577,7 @@ public class MediaBindingBean {
@Define("runtime") @Define("runtime")
public Integer getRuntime() { public Integer getRuntime() {
Object runtime = getMetaInfo().getProperty("runtime"); return (Integer) getMetaInfo().getProperty("runtime");
return runtime instanceof Integer ? (Integer) runtime : Integer.parseInt(runtime.toString());
} }
@Define("actors") @Define("actors")
@ -900,16 +901,23 @@ public class MediaBindingBean {
return String.format("%.1f", getFileSize() / Math.pow(1000, 3)); return String.format("%.1f", getFileSize() / Math.pow(1000, 3));
} }
@Define("encodedDate")
public SimpleDate getEncodedDate() {
String date = getMediaInfo(StreamKind.General, 0, "Encoded_Date"); // e.g. UTC 2008-01-08 19:54:39
ZonedDateTime time = ZonedDateTime.parse(date, DateTimeFormatter.ofPattern("zzz uuuu-MM-dd HH:mm:ss"));
return new SimpleDate(time);
}
@Define("today")
public SimpleDate getToday() {
return new SimpleDate(LocalDate.now());
}
@Define("home") @Define("home")
public File getUserHome() { public File getUserHome() {
return ApplicationFolder.UserHome.getCanonicalFile(); return ApplicationFolder.UserHome.getCanonicalFile();
} }
@Define("now")
public Date getNow() {
return new Date();
}
@Define("output") @Define("output")
public File getUserDefinedOutputFolder() throws IOException { public File getUserDefinedOutputFolder() throws IOException {
return new File(Settings.getApplicationArguments().output).getCanonicalFile(); return new File(Settings.getApplicationArguments().output).getCanonicalFile();

View File

@ -3,9 +3,10 @@ package net.filebot.web;
import java.io.Serializable; import java.io.Serializable;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;
import java.time.temporal.Temporal;
import java.util.Arrays; import java.util.Arrays;
import java.util.Locale; import java.util.Locale;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -27,12 +28,12 @@ public class SimpleDate implements Serializable, Comparable<Object> {
this.day = day; this.day = day;
} }
public SimpleDate(LocalDate date) { public SimpleDate(Temporal date) {
this(date.getYear(), date.getMonthValue(), date.getDayOfMonth()); this(date.get(ChronoField.YEAR), date.get(ChronoField.MONTH_OF_YEAR), date.get(ChronoField.DAY_OF_MONTH));
} }
public SimpleDate(long t) { public SimpleDate(long t) {
this(LocalDateTime.ofInstant(Instant.ofEpochMilli(t), ZoneId.systemDefault()).toLocalDate()); this(Instant.ofEpochMilli(t).atZone(ZoneId.systemDefault()));
} }
public int getYear() { public int getYear() {