Show
Ignore:
Timestamp:
12/10/09 16:30:12 (2 years ago)
Author:
olger
Message:

Change migrate to convert worknotes and datetimes in patient treatment documents

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • his/tags/1.9.7/support/util/src/main/java/org/joiningtracks/his/support/util/xstream/converter/DateTimeISO8601Converter.java

    r1817 r2452  
    1818import com.thoughtworks.xstream.converters.SingleValueConverter; 
    1919import org.apache.commons.lang.StringUtils; 
     20import org.joda.time.DateTime; 
    2021import org.joda.time.LocalDate; 
    2122import org.joda.time.format.DateTimeFormat; 
     23import org.joda.time.format.ISODateTimeFormat; 
    2224 
    2325/** 
    2426 * Used to serialize and de-serailize local date. 
    2527 * 
    26  * @author Aparna Chaudhary 
     28 * @author Olger Warnier 
    2729 */ 
    28 public class LocalDateConverter implements SingleValueConverter { 
     30public class DateTimeISO8601Converter implements SingleValueConverter { 
    2931 
    30     private String dateFormat; 
    3132 
    32     public LocalDateConverter() { 
     33    public DateTimeISO8601Converter() { 
    3334 
    3435    } 
    3536 
    36     public LocalDateConverter(String dateFormat) { 
    37         this.dateFormat = dateFormat; 
    38     } 
    39  
    4037    public boolean canConvert(Class type) { 
    41         return type.equals(LocalDate.class); 
     38        return type.equals(DateTime.class); 
    4239    } 
    4340 
     
    4542        if (StringUtils.isBlank(str)) { 
    4643            throw new IllegalArgumentException( 
    47                     "The specified LocalDate string cannot be null"); 
     44                    "The specified DateTime string cannot be null"); 
    4845        } else { 
    49             return DateTimeFormat.forPattern(dateFormat).parseDateTime(str).toLocalDate(); 
     46            return new DateTime(str); 
    5047        } 
    5148    } 
    5249 
    5350    public String toString(Object obj) { 
    54         if (dateFormat != null) { 
    55             return ((LocalDate) obj).toString(dateFormat); 
    56         } else { 
    57             return obj.toString(); 
    58         } 
     51        return ISODateTimeFormat.dateTime().print((DateTime)obj); 
    5952    } 
    6053}