1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-17 06:45:06 -05:00

Make sure that SimpleFormat.format(String) continues to work for custom formats

This commit is contained in:
Reinhard Pointner 2016-02-22 04:46:37 +00:00
parent 158119a26b
commit fe49ebf36d

View File

@ -5,8 +5,10 @@ import java.time.Instant;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Arrays; import java.util.Arrays;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -90,6 +92,14 @@ public class SimpleDate implements Serializable, Comparable<Object> {
return new SimpleDate(year, month, day); return new SimpleDate(year, month, day);
} }
public String format(String pattern) {
return DateTimeFormatter.ofPattern(pattern, Locale.ENGLISH).format(this.toLocalDate());
}
public LocalDate toLocalDate() {
return LocalDate.of(year, month, day);
}
@Override @Override
public String toString() { public String toString() {
return String.format("%04d-%02d-%02d", year, month, day); return String.format("%04d-%02d-%02d", year, month, day);
@ -105,6 +115,6 @@ public class SimpleDate implements Serializable, Comparable<Object> {
return null; return null;
} }
public static final Pattern DATE_FORMAT = Pattern.compile("(\\d{4}).(\\d{1,2}).(\\d{1,2})"); public static final Pattern DATE_FORMAT = Pattern.compile("(\\d{4})\\D(\\d{1,2})\\D(\\d{1,2})");
} }