File tree Expand file tree Collapse file tree 2 files changed +26
-8
lines changed
rwx/src/main/java/org/commonjava/rwx/vocab Expand file tree Collapse file tree 2 files changed +26
-8
lines changed Original file line number Diff line number Diff line change @@ -169,16 +169,34 @@ public String toString( final Object value )
169
169
DATETIME ( new ValueCoercion ( "DATETIME-to-String (" + DATETIME_FORMAT + ")" )
170
170
{
171
171
@ Override
172
- public Object fromString ( final String value ) throws CoercionException
172
+ public Object fromString ( String value ) throws CoercionException
173
173
{
174
- try
174
+ if ( value == null )
175
175
{
176
- String val = value == null ? null : value .trim ();
177
- return val == null ? null : new SimpleDateFormat ( DATETIME_FORMAT ).parse ( value );
176
+ return null ;
178
177
}
179
- catch ( final ParseException e )
178
+ value = value .trim ();
179
+ Date obj = null ;
180
+ ParseException exception = null ;
181
+ for ( String format : DATETIME_FORMAT )
182
+ {
183
+ try
184
+ {
185
+ obj = new SimpleDateFormat ( format ).parse ( value );
186
+ break ;
187
+ }
188
+ catch ( final ParseException e )
189
+ {
190
+ exception = e ;
191
+ }
192
+ }
193
+ if ( obj != null )
194
+ {
195
+ return obj ;
196
+ }
197
+ else
180
198
{
181
- throw new CoercionException ( "Cannot parse date: '" + value + "'." , e );
199
+ throw new CoercionException ( "Cannot parse date: '" + value + "'." , exception );
182
200
}
183
201
}
184
202
@@ -187,7 +205,7 @@ public String toString( final Object value ) throws CoercionException
187
205
{
188
206
try
189
207
{
190
- return value == null ? null : new SimpleDateFormat ( DATETIME_FORMAT ).format ( (Date ) value );
208
+ return value == null ? null : new SimpleDateFormat ( DATETIME_FORMAT [ 0 ] ).format ( (Date ) value );
191
209
}
192
210
catch ( final ClassCastException e )
193
211
{
Original file line number Diff line number Diff line change @@ -44,6 +44,6 @@ public class XmlRpcConstants
44
44
45
45
public static final String NIL = "nil" ;
46
46
47
- public static final String DATETIME_FORMAT = "yyyyMMdd'T'HHmmss" ;
47
+ public static final String [] DATETIME_FORMAT = { "yyyyMMdd'T'HHmmss" , "yyyyMMdd'T'HH:mm:ss" } ;
48
48
49
49
}
You can’t perform that action at this time.
0 commit comments