Add time units strings and utilities
This commit is contained in:
parent
fa3974bf3a
commit
27f61e049d
96 changed files with 19600 additions and 0 deletions
29
timeago-parser/raw/java/Utils.java
Normal file
29
timeago-parser/raw/java/Utils.java
Normal file
|
@ -0,0 +1,29 @@
|
|||
import java.util.*;
|
||||
|
||||
public class Utils {
|
||||
|
||||
static Comparator<String> compareByNumber() {
|
||||
return new Comparator<String>() {
|
||||
@Override
|
||||
public int compare(String o1, String o2) {
|
||||
return extractInt(o1) - extractInt(o2);
|
||||
}
|
||||
|
||||
private int extractInt(String s) {
|
||||
String num = s.replaceAll("\\D", "");
|
||||
return num.isEmpty() ? 0 : Integer.parseInt(num);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
static Comparator<Object> compareByUnitName() {
|
||||
return new Comparator<Object>() {
|
||||
private final List<String> ORDER = Arrays.asList("seconds", "minutes", "hours", "days", "weeks", "months", "years");
|
||||
|
||||
@Override
|
||||
public int compare(Object o1, Object o2) {
|
||||
return Integer.compare(ORDER.indexOf(o1.toString()), ORDER.indexOf(o2.toString()));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue