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