calculatedFields.put(aFieldName, aField);
}
- public void addDateField(String aDestinationFieldName, String aSourceFieldName) {
- addCalculatedField(aDestinationFieldName, new DateField(aSourceFieldName));
+ public void addMirDateField(String aDestinationFieldName, String aSourceFieldName) {
+ addCalculatedField(aDestinationFieldName, new MirDateField(aSourceFieldName));
+ }
+
+ public void addDBDateField(String aDestinationFieldName, String aSourceFieldName) {
+ addCalculatedField(aDestinationFieldName, new DBDateField(aSourceFieldName));
}
public interface CalculatedField {
public Object getValue(EntityAdapter anEntityAdapter);
}
- private class DateField implements CalculatedField {
+ private class MirDateField implements CalculatedField {
private String fieldName;
- public DateField(String aFieldName) {
+ public MirDateField(String aFieldName) {
fieldName = aFieldName;
}
month = Integer.parseInt(textValue.substring(4,6));
day = Integer.parseInt(textValue.substring(6,8));
- calendar.set(year, month, day);
+ calendar.set(year, month-1, day);
date = calendar.getTime();
;
result.put("date", date);
result.put("formatted", new DateToMapAdapter(date));
-/* result.put("year", textValue.substring(0,4));
- result.put("month", textValue.substring(4,6));
- result.put("day", textValue.substring(6,8));
-*/ }
+ }
+ catch (Throwable t) {
+ result=null;
+ }
+ }
+
+ return result;
+
+ }
+
+ }
+
+ private class DBDateField implements CalculatedField {
+ private String fieldName;
+
+ public DBDateField(String aFieldName) {
+ fieldName = aFieldName;
+ }
+
+ public Object getValue(EntityAdapter anEntityAdapter) {
+
+ Map result = new HashMap();
+ String textValue = anEntityAdapter.getEntity().getValue(fieldName);
+ Calendar calendar = GregorianCalendar.getInstance();
+ int year;
+ int month;
+ int day;
+ int hours;
+ int minutes;
+
+ Date date;
+
+ if (textValue!=null) {
+ try {
+ year = Integer.parseInt(textValue.substring(0,4));
+ month = Integer.parseInt(textValue.substring(5,7));
+ day = Integer.parseInt(textValue.substring(8,10));
+ hours = Integer.parseInt(textValue.substring(11,13));
+ minutes = Integer.parseInt(textValue.substring(14,16));
+
+ calendar.set(year, month-1, day, hours, minutes);
+ date = calendar.getTime();
+
+ result.put("date", date);
+ result.put("formatted", new DateToMapAdapter(date));
+ result.put("raw", textValue);
+ }
catch (Throwable t) {
result=null;
-/* result.put("date", null);
- result.put("year", null);
- result.put("month", null);
- result.put("day", null);
-*/ }
+ }
}
return result;