Improved support for custom Duration formats

This commit is contained in:
Reinhard Pointner 2017-03-27 19:39:30 +08:00
parent fb81a895b8
commit 3511f08344
2 changed files with 8 additions and 5 deletions

View File

@ -14,8 +14,10 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.attribute.BasicFileAttributeView;
import java.nio.file.attribute.BasicFileAttributes;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAmount;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@ -551,7 +553,11 @@ public class ExpressionFormatMethods {
}
public static String format(Temporal self, String pattern) {
return DateTimeFormatter.ofPattern(pattern).format(self);
return DateTimeFormatter.ofPattern(pattern, Locale.ENGLISH).format(self);
}
public static String format(TemporalAmount self, String pattern) {
return DateTimeFormatter.ofPattern(pattern, Locale.ENGLISH).format(LocalTime.MIDNIGHT.plus(self));
}
/**

View File

@ -835,10 +835,7 @@ public class MediaBindingBean {
@Define("hours")
public String getHours() {
Duration d = getDuration();
// use RATIO instead of COLON for file name compatibility (see https://unicode-table.com/en/2236/)
return String.format("%d%02d", d.toHours(), d.minusHours(d.toHours()).toMinutes());
return ExpressionFormatMethods.format(getDuration(), "H:mm");
}
@Define("media")