1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.comparator;
17
18 import org.kuali.rice.core.web.format.DateFormatter;
19
20 import java.io.Serializable;
21 import java.util.Comparator;
22 import java.util.Date;
23
24 public class TemporalValueComparator implements Comparator, Serializable {
25 private static final TemporalValueComparator theInstance = new TemporalValueComparator();
26
27 public TemporalValueComparator() {
28 }
29
30 public static TemporalValueComparator getInstance() {
31 return theInstance;
32 }
33
34 public int compare(Object o1, Object o2) {
35
36
37 if (null == o1 || null == o2) {
38 return null == o1 && null == o2 ? 0 : null == o1 ? -1 : 1;
39 }
40
41 String s1 = (String) o1;
42 String s2 = (String) o2;
43
44 DateFormatter f1 = new DateFormatter();
45
46 Date d1 = (Date) f1.convertFromPresentationFormat(s1);
47 Date d2 = (Date) f1.convertFromPresentationFormat(s2);
48
49 if (null == d1 || null == d2) {
50 return null == d1 && null == d2 ? 0 : null == d1 ? -1 : 1;
51 }
52
53 return d1.equals(d2) ? 0 : d1.before(d2) ? -1 : 1;
54 }
55 }