small bugfix regarding dc formatted time
[mir.git] / source / mir / util / DateToMapAdapter.java
1 package mir.util;
2
3 import java.util.*;
4 import java.text.*;
5
6 import mir.misc.*;
7
8 public class DateToMapAdapter extends AbstractMap {
9   Date date;
10
11   public DateToMapAdapter(Date aDate) {
12     date = aDate;
13   }
14
15   public Object get(Object aKey) {
16     if (aKey instanceof String) {
17       try {
18         // ML: quick fix to allow for the dc encoding now...
19         if (((String) aKey).equals("dc")) {
20           GregorianCalendar calendar = new GregorianCalendar();
21           calendar.setTime(date);
22           return StringUtil.date2w3DateTime(calendar);
23         }
24         else
25           return new SimpleDateFormat((String) aKey).format(date);
26       }
27       catch (Throwable t) {
28         throw new RuntimeException( "Can't format date with format " + (String) aKey + ": " + t.getMessage());
29       }
30     }
31     else return null;
32   }
33
34   public Set entrySet() {
35     return new HashSet();
36   }
37 }