| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.student.common.validator.old; |
| 17 | |
|
| 18 | |
import java.text.SimpleDateFormat; |
| 19 | |
import java.util.Date; |
| 20 | |
|
| 21 | 21 | public class ServerDateParser implements DateParser { |
| 22 | 2 | private static ThreadLocal<SimpleDateFormat[]> formats = new ThreadLocal<SimpleDateFormat[]>() { |
| 23 | |
|
| 24 | |
protected SimpleDateFormat[] initialValue() { |
| 25 | 1 | return new SimpleDateFormat[] { |
| 26 | |
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"), |
| 27 | |
new SimpleDateFormat("yyyy-MM-dd") |
| 28 | |
}; |
| 29 | |
} |
| 30 | |
|
| 31 | |
}; |
| 32 | |
|
| 33 | |
public Date parseDate(String input) { |
| 34 | 6 | Date result = null; |
| 35 | |
|
| 36 | 12 | for (SimpleDateFormat format : formats.get()) { |
| 37 | |
try { |
| 38 | 12 | result = format.parse(input); |
| 39 | 6 | } catch (Exception e) { |
| 40 | |
|
| 41 | 6 | } |
| 42 | 12 | if (result != null) { |
| 43 | 6 | break; |
| 44 | |
} |
| 45 | |
|
| 46 | |
} |
| 47 | |
|
| 48 | 6 | if (result == null) { |
| 49 | 0 | throw new DateParseException("Invalid date value: " + input); |
| 50 | |
} |
| 51 | |
|
| 52 | 6 | return result; |
| 53 | |
} |
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
@Override |
| 59 | |
public String toString(Date date) { |
| 60 | 0 | String result = null; |
| 61 | 0 | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-ddTHH:mm:ss,SSS"); |
| 62 | 0 | result = format.format(date); |
| 63 | |
|
| 64 | 0 | return result; |
| 65 | |
} |
| 66 | |
} |