Changeset 2452 for his/tags/1.9.7/support
- Timestamp:
- 12/10/09 16:30:12 (2 years ago)
- 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 18 18 import com.thoughtworks.xstream.converters.SingleValueConverter; 19 19 import org.apache.commons.lang.StringUtils; 20 import org.joda.time.DateTime; 20 21 import org.joda.time.LocalDate; 21 22 import org.joda.time.format.DateTimeFormat; 23 import org.joda.time.format.ISODateTimeFormat; 22 24 23 25 /** 24 26 * Used to serialize and de-serailize local date. 25 27 * 26 * @author Aparna Chaudhary28 * @author Olger Warnier 27 29 */ 28 public class LocalDateConverter implements SingleValueConverter {30 public class DateTimeISO8601Converter implements SingleValueConverter { 29 31 30 private String dateFormat;31 32 32 public LocalDateConverter() {33 public DateTimeISO8601Converter() { 33 34 34 35 } 35 36 36 public LocalDateConverter(String dateFormat) {37 this.dateFormat = dateFormat;38 }39 40 37 public boolean canConvert(Class type) { 41 return type.equals( LocalDate.class);38 return type.equals(DateTime.class); 42 39 } 43 40 … … 45 42 if (StringUtils.isBlank(str)) { 46 43 throw new IllegalArgumentException( 47 "The specified LocalDate string cannot be null");44 "The specified DateTime string cannot be null"); 48 45 } else { 49 return DateTimeFormat.forPattern(dateFormat).parseDateTime(str).toLocalDate();46 return new DateTime(str); 50 47 } 51 48 } 52 49 53 50 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); 59 52 } 60 53 }
