1 package net.sourceforge.blogentis.utils.tools;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import java.text.DateFormat;
26 import java.text.SimpleDateFormat;
27 import java.util.ArrayList;
28 import java.util.Calendar;
29 import java.util.Iterator;
30 import java.util.List;
31
32 import net.sourceforge.blogentis.rss.RSSItem;
33
34 import org.apache.turbine.services.pull.ApplicationTool;
35
36 public class DateFormatterTool implements ApplicationTool {
37 protected static DateFormat mfTime = new SimpleDateFormat("HH:mm");
38
39 protected static DateFormat mfDate = new SimpleDateFormat(
40 "EEEE, dd MMMM yyyy");
41
42 protected static DateFormat mfFull = new SimpleDateFormat(
43 "EEEE, dd MMMM yyyy, HH:mm");
44
45 public void init(Object data) {}
46
47 public void refresh() {}
48
49 public String formatTime(Object o) {
50 return mfTime.format(o);
51 }
52
53 public String formatDate(Object o) {
54 return mfDate.format(o);
55 }
56
57 public String formatDateTime(Object o) {
58 return mfFull.format(o);
59 }
60
61 public String format(String format, Object o) {
62
63 return new SimpleDateFormat(format).format(o);
64 }
65
66 public List sortByDate(List l) {
67 ArrayList ret = new ArrayList(2);
68 ArrayList todayItems = null;
69 int oldDay = -2;
70 Calendar oldCal = Calendar.getInstance();
71 for(Iterator i = l.iterator(); i.hasNext();) {
72 RSSItem pi = (RSSItem)i.next();
73 oldCal.setTime(pi.getPostedTime());
74 if (oldCal.get(Calendar.DAY_OF_YEAR) != oldDay) {
75 todayItems = new ArrayList(1);
76 ret.add(todayItems);
77 oldDay = oldCal.get(Calendar.DAY_OF_YEAR);
78 }
79 todayItems.add(pi);
80 }
81 return ret;
82 }
83 }