Coverage Report - org.kuali.student.contract.model.util.DateUtility
 
Classes in this File Line Coverage Branch Coverage Complexity
DateUtility
0%
0/18
0%
0/8
4.333
 
 1  
 /*
 2  
  * Copyright 2010 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may        obtain a copy of the License at
 7  
  *
 8  
  *         http://www.osedu.org/licenses/ECL-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.student.contract.model.util;
 17  
 
 18  
 import java.text.DateFormat;
 19  
 import java.text.ParseException;
 20  
 import java.text.SimpleDateFormat;
 21  
 import java.util.Date;
 22  
 
 23  
 import org.kuali.student.contract.exception.DictionaryExecutionException;
 24  
 
 25  
 /**
 26  
  *
 27  
  * @author nwright
 28  
  */
 29  0
 public class DateUtility
 30  
 {
 31  
 
 32  
  public String asYMD (String date)
 33  
   throws ParseException
 34  
  {
 35  0
   if (date == null)
 36  
   {
 37  0
    return null;
 38  
   }
 39  0
   return asYMD (asDate (date));
 40  
  }
 41  
 
 42  
  public Date asDate (String date)
 43  
   throws ParseException
 44  
  {
 45  0
   if (date == null)
 46  
   {
 47  0
    return null;
 48  
   }
 49  0
   String[] formats =
 50  
   {
 51  
    "yyyy-MM-dd",
 52  
    "MM/dd/yyyy"
 53  
   };
 54  0
   ParseException pe = null;
 55  0
   for (int i = 0; i < formats.length; i ++)
 56  
   {
 57  0
    DateFormat df = new SimpleDateFormat (formats[i]);
 58  
    try
 59  
    {
 60  0
     return df.parse (date);
 61  
    }
 62  0
    catch (ParseException e)
 63  
    {
 64  0
     pe = e;
 65  
    }
 66  
   }
 67  0
   throw pe;
 68  
  }
 69  
 
 70  
  public String asYMD (Date date)
 71  
  {
 72  0
   if (date == null)
 73  
   {
 74  0
    return null;
 75  
   }
 76  0
   DateFormat df = new SimpleDateFormat ("yyyy-MM-dd");
 77  0
   return df.format (date);
 78  
  }
 79  
 
 80  
 }