Chromium Code Reviews| Index: java/org/chromium/distiller/DomUtil.java |
| diff --git a/java/org/chromium/distiller/DomUtil.java b/java/org/chromium/distiller/DomUtil.java |
| index b99f73df029ec3df3ddff1c0e62f472a3e3bebdf..ea3e348a1c712b8e52e36ad566f33f3998484cdf 100644 |
| --- a/java/org/chromium/distiller/DomUtil.java |
| +++ b/java/org/chromium/distiller/DomUtil.java |
| @@ -15,6 +15,8 @@ import com.google.gwt.dom.client.NodeList; |
| import com.google.gwt.dom.client.Style; |
| import com.google.gwt.dom.client.VideoElement; |
| import com.google.gwt.http.client.URL; |
| +import com.google.gwt.regexp.shared.MatchResult; |
| +import com.google.gwt.regexp.shared.RegExp; |
| import java.util.ArrayList; |
| import java.util.HashMap; |
| @@ -433,6 +435,38 @@ public class DomUtil { |
| return nodes; |
| } |
| + public static String formatDuration(String duration) { |
|
wychen
2016/03/14 22:58:42
I18n and l10n might be difficult. Singular/plural
|
| + RegExp pattern = RegExp.compile("^P(?:([0-9]+)Y)?" + |
| + "(?:([0-9]+)M)?(?:([0-9]+)W)?(?:([0-9]+)D)?" + |
| + "(T(?:([0-9]+)H)?(?:([0-9]+)M)?(?:([0-9]+)S)?)?$", "i"); |
| + MatchResult matchResult = pattern.exec(duration); |
| + List<String> result = new ArrayList<>(); |
| + if (matchResult != null) { |
| + if (matchResult.getGroup(1) != null) { |
| + result.add(matchResult.getGroup(1) + " year(s)"); |
| + } |
| + if (matchResult.getGroup(2) != null) { |
| + result.add(matchResult.getGroup(2) + " month(s)"); |
| + } |
| + if (matchResult.getGroup(3) != null) { |
| + result.add(matchResult.getGroup(3) + " week(s)"); |
| + } |
| + if (matchResult.getGroup(4) != null) { |
| + result.add(matchResult.getGroup(4) + " day(s)"); |
| + } |
| + if (matchResult.getGroup(6) != null) { |
| + result.add(matchResult.getGroup(6) + " hour(s)"); |
| + } |
| + if (matchResult.getGroup(7) != null) { |
| + result.add(matchResult.getGroup(7) + " minute(s)"); |
| + } |
| + if (matchResult.getGroup(8) != null) { |
| + result.add(matchResult.getGroup(8) + " second(s)"); |
| + } |
| + } |
| + return join(result.toArray(), " "); |
| + } |
| + |
| /** |
| * Generate HTML/text output for a given node tree/subree. This will ignore hidden |
| * elements. |
| @@ -461,4 +495,8 @@ public class DomUtil { |
| public static native Element getFirstElementChild(Document document) /*-{ |
| return document.firstElementChild; |
| }-*/; |
| + |
| + public static native String join(Object[] list, String conjunction) /*-{ |
| + return list.join(conjunction); |
| + }-*/; |
| } |