From bddf3e516b68b71b059807240172e12e85b9ce35 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Tue, 9 Aug 2016 23:46:03 +0800 Subject: [PATCH] Refactor Date {now} to SimpleDate {today} --- .../net/filebot/format/MediaBindingBean.java | 24 ++++++++++++------- source/net/filebot/web/SimpleDate.java | 9 +++---- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/source/net/filebot/format/MediaBindingBean.java b/source/net/filebot/format/MediaBindingBean.java index 7bf4b880..22737755 100644 --- a/source/net/filebot/format/MediaBindingBean.java +++ b/source/net/filebot/format/MediaBindingBean.java @@ -22,8 +22,10 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.math.BigDecimal; import java.math.RoundingMode; +import java.time.LocalDate; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; -import java.util.Date; import java.util.Iterator; import java.util.List; import java.util.Locale; @@ -575,8 +577,7 @@ public class MediaBindingBean { @Define("runtime") public Integer getRuntime() { - Object runtime = getMetaInfo().getProperty("runtime"); - return runtime instanceof Integer ? (Integer) runtime : Integer.parseInt(runtime.toString()); + return (Integer) getMetaInfo().getProperty("runtime"); } @Define("actors") @@ -900,16 +901,23 @@ public class MediaBindingBean { 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") public File getUserHome() { return ApplicationFolder.UserHome.getCanonicalFile(); } - @Define("now") - public Date getNow() { - return new Date(); - } - @Define("output") public File getUserDefinedOutputFolder() throws IOException { return new File(Settings.getApplicationArguments().output).getCanonicalFile(); diff --git a/source/net/filebot/web/SimpleDate.java b/source/net/filebot/web/SimpleDate.java index a578af95..1b37bd23 100644 --- a/source/net/filebot/web/SimpleDate.java +++ b/source/net/filebot/web/SimpleDate.java @@ -3,9 +3,10 @@ package net.filebot.web; import java.io.Serializable; import java.time.Instant; import java.time.LocalDate; -import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoField; +import java.time.temporal.Temporal; import java.util.Arrays; import java.util.Locale; import java.util.regex.Matcher; @@ -27,12 +28,12 @@ public class SimpleDate implements Serializable, Comparable { this.day = day; } - public SimpleDate(LocalDate date) { - this(date.getYear(), date.getMonthValue(), date.getDayOfMonth()); + public SimpleDate(Temporal date) { + this(date.get(ChronoField.YEAR), date.get(ChronoField.MONTH_OF_YEAR), date.get(ChronoField.DAY_OF_MONTH)); } public SimpleDate(long t) { - this(LocalDateTime.ofInstant(Instant.ofEpochMilli(t), ZoneId.systemDefault()).toLocalDate()); + this(Instant.ofEpochMilli(t).atZone(ZoneId.systemDefault())); } public int getYear() {