X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmir%2Fentity%2Fadapter%2FEntityAdapterDefinition.java;h=9a888fb2d86ae7a13eaf9f78fb487501c1ea2da1;hb=3389d56d4d82089033fd83f9c8758126ffd7da44;hp=1c60e88a1f22654541faa04542971633dcb52c30;hpb=f9a7655d20e23418320dd552f257893f25268d16;p=mir.git diff --git a/source/mir/entity/adapter/EntityAdapterDefinition.java b/source/mir/entity/adapter/EntityAdapterDefinition.java index 1c60e88a..9a888fb2 100755 --- a/source/mir/entity/adapter/EntityAdapterDefinition.java +++ b/source/mir/entity/adapter/EntityAdapterDefinition.java @@ -28,18 +28,22 @@ public class EntityAdapterDefinition { 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; } @@ -59,24 +63,63 @@ public class EntityAdapterDefinition { 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;