Coverage Report - org.kuali.rice.core.web.format.TimestampAMPMFormatter
 
Classes in this File Line Coverage Branch Coverage Complexity
TimestampAMPMFormatter
0%
0/12
0%
0/8
4
 
 1  
 /**
 2  
  * Copyright 2005-2011 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.opensource.org/licenses/ecl2.php
 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.rice.core.web.format;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.core.api.CoreConstants;
 20  
 import org.kuali.rice.core.api.datetime.DateTimeService;
 21  
 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
 22  
 import org.kuali.rice.core.api.util.RiceKeyConstants;
 23  
 
 24  
 import java.text.ParseException;
 25  
 import java.util.Date;
 26  
 
 27  
 /**
 28  
  * This class is used to format timestamp objects.
 29  
  */
 30  
 
 31  0
 public class TimestampAMPMFormatter extends Formatter {
 32  
     private static final long serialVersionUID = 7612442662886603084L;
 33  
 
 34  
     private transient DateTimeService dateTimeService;
 35  
 
 36  
     /**
 37  
      * Unformats its argument and return a java.util.Date instance initialized with the resulting string.
 38  
      * 
 39  
      * @return a java.util.Date intialized with the provided string
 40  
      */
 41  
     public Object convertToObject(String target) {
 42  
         try {
 43  0
                 return getDateTimeService().convertToSqlTimestamp(target);
 44  
         }
 45  0
         catch (ParseException e) {
 46  0
             throw new FormatException("parsing", RiceKeyConstants.ERROR_DATE_TIME, target, e);
 47  
         }
 48  
     }
 49  
 
 50  
 
 51  
     /**
 52  
      * Returns a string representation of its argument, formatted as a date with the "MM/dd/yyyy h:mm a" format.
 53  
      * 
 54  
      * @return a formatted String
 55  
      */
 56  
     public Object format(Object value) {
 57  0
         if (value == null) {
 58  0
             return null;
 59  
         }
 60  0
         if (value instanceof String && StringUtils.isEmpty((String) value)) {
 61  0
             return null;
 62  
         }
 63  0
         return getDateTimeService().toDateTimeString((Date)value);
 64  
     }
 65  
     
 66  
     protected DateTimeService getDateTimeService() {
 67  0
             if (this.dateTimeService == null) {
 68  0
                     this.dateTimeService = GlobalResourceLoader.getService(CoreConstants.Services.DATETIME_SERVICE);
 69  
             }
 70  0
             return this.dateTimeService;
 71  
     }
 72  
 }