diff --git a/jpos/src/main/java/org/jpos/iso/ISODate.java b/jpos/src/main/java/org/jpos/iso/ISODate.java index 77d918ef0a..e0304570e0 100644 --- a/jpos/src/main/java/org/jpos/iso/ISODate.java +++ b/jpos/src/main/java/org/jpos/iso/ISODate.java @@ -20,6 +20,7 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.time.Duration; import java.util.*; /** @@ -349,4 +350,21 @@ private static int calculateNearestFullYear(int year, Calendar now) { } return possibleYear; } + + public static String formatDuration(Duration d) { + long days = d.toDays(); + long hours = d.toHoursPart(); + long minutes = d.toMinutesPart(); + long seconds = d.toSecondsPart(); + StringJoiner sj = new StringJoiner(", "); + if (days > 0) + sj.add(days + "d"); + if (hours > 0) + sj.add(hours + "h"); + if (minutes > 0) + sj.add(minutes + "m"); + if (seconds > 0 || sj.length() == 0) + sj.add(seconds + "s"); + return sj.toString(); + } }