Coverage Report - org.kuali.student.common.validator.old.ServerDateParser
 
Classes in this File Line Coverage Branch Coverage Complexity
ServerDateParser
68%
11/16
66%
4/6
2.667
ServerDateParser$1
100%
2/2
N/A
2.667
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 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  
                     // just eat it
 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  
      * @see org.kuali.student.common.validator.old.DateParser#toString(java.util.Date)
 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  
 }