|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
DateConverter.java | - | 87.5% | 100% | 92.3% |
|
1 |
package com.thoughtworks.xstream.converters.basic;
|
|
2 |
|
|
3 |
import com.thoughtworks.xstream.converters.ConversionException;
|
|
4 |
|
|
5 |
import java.text.DateFormat;
|
|
6 |
import java.text.ParseException;
|
|
7 |
import java.text.SimpleDateFormat;
|
|
8 |
import java.util.Date;
|
|
9 |
|
|
10 |
|
|
11 |
public class DateConverter extends AbstractBasicConverter { |
|
12 |
|
|
13 |
private DateFormat dateFormat;
|
|
14 |
|
|
15 | 218 |
public boolean canConvert(Class type) { |
16 | 218 |
return type.equals(Date.class); |
17 |
} |
|
18 |
|
|
19 | 35 |
public DateConverter(DateFormat dateFormat) {
|
20 | 35 |
this.dateFormat = dateFormat;
|
21 |
} |
|
22 |
|
|
23 | 35 |
public DateConverter() {
|
24 | 35 |
this(new SimpleDateFormat("yyyy-MM-dd HH:mm:ssa")); |
25 |
} |
|
26 |
|
|
27 | 1 |
protected Object fromString(String str) {
|
28 | 1 |
try {
|
29 | 1 |
return dateFormat.parse(str);
|
30 |
} catch (ParseException e) {
|
|
31 | 0 |
throw new ConversionException("Cannot parse date " + str, e); |
32 |
} |
|
33 |
} |
|
34 |
|
|
35 | 1 |
protected String toString(Object obj) {
|
36 | 1 |
Date date = (Date) obj; |
37 | 1 |
return dateFormat.format(date);
|
38 |
} |
|
39 |
|
|
40 |
} |
|
41 |
|
|