Coverage Report - org.kuali.student.enrollment.class2.acal.dto.TimeSetWrapper
 
Classes in this File Line Coverage Branch Coverage Complexity
TimeSetWrapper
0%
0/61
0%
0/18
1.789
 
 1  
 /**
 2  
  * Copyright 2012 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.enrollment.class2.acal.dto;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.student.enrollment.class2.acal.util.CommonUtils;
 20  
 
 21  
 import java.text.DateFormat;
 22  
 import java.text.SimpleDateFormat;
 23  
 import java.util.Date;
 24  
 
 25  
 /**
 26  
  * This class //TODO ...
 27  
  *
 28  
  * @author Kuali Student Team
 29  
  */
 30  0
 public class TimeSetWrapper {
 31  
     private Date startDate;
 32  
     private Date endDate;
 33  
     private String startTime;
 34  
     private String startTimeAmPm;
 35  
     private String endTime;
 36  
     private String endTimeAmPm;
 37  
     private boolean allDay;
 38  
     private boolean dateRange;
 39  
 
 40  
     //This is needed for view purpose as we're setting the end date as null sothat it wont display in the ui
 41  
     protected Date endDateUI;
 42  
 
 43  
     protected void buildDateAndTime(){
 44  
 
 45  
         //This is needed to display enddate for readonly view (not needed for edit mode).
 46  0
         endDateUI = getEndDate();
 47  
 
 48  
         // If not all day, set start/end time in the wrapper
 49  0
         if (!isAllDay()){
 50  
 
 51  0
             DateFormat dfm = new SimpleDateFormat("hh:mm");
 52  
 
 53  0
             if (getEndDate() != null){
 54  0
                 setStartTime(dfm.format(getStartDate()));
 55  0
                 setEndTime(dfm.format(getEndDate()));
 56  
 
 57  0
                 dfm = new SimpleDateFormat("a");
 58  0
                 setStartTimeAmPm(dfm.format(getStartDate()));
 59  0
                 setEndTimeAmPm(dfm.format(getEndDate()));
 60  
 
 61  0
                 String startDate = CommonUtils.formatDate(getStartDate());
 62  0
                 String endDate = CommonUtils.formatDate(getEndDate());
 63  
 
 64  0
                 if (StringUtils.equals(startDate,endDate)){
 65  0
                     setDateRange(false);
 66  0
                     setEndDate(null);
 67  
                 }else{
 68  0
                     setDateRange(true);
 69  
                 }
 70  
             }
 71  
         }
 72  0
     }
 73  
 
 74  
     public Date getStartDate() {
 75  0
         return startDate;
 76  
     }
 77  
 
 78  
     public void setStartDate(Date startDate) {
 79  0
         this.startDate = startDate;
 80  0
     }
 81  
 
 82  
     public Date getEndDate() {
 83  0
         return endDate;
 84  
     }
 85  
 
 86  
     public void setEndDate(Date endDate) {
 87  0
         this.endDate = endDate;
 88  0
     }
 89  
 
 90  
     public String getStartTime() {
 91  0
         return startTime;
 92  
     }
 93  
 
 94  
     public void setStartTime(String startTime) {
 95  0
         this.startTime = startTime;
 96  0
     }
 97  
 
 98  
     public String getStartTimeAmPm() {
 99  0
         return startTimeAmPm;
 100  
     }
 101  
 
 102  
     public void setStartTimeAmPm(String startTimeAmPm) {
 103  0
         this.startTimeAmPm = startTimeAmPm;
 104  0
     }
 105  
 
 106  
     public String getEndTime() {
 107  0
         return endTime;
 108  
     }
 109  
 
 110  
     public void setEndTime(String endTime) {
 111  0
         this.endTime = endTime;
 112  0
     }
 113  
 
 114  
     public String getEndTimeAmPm() {
 115  0
         return endTimeAmPm;
 116  
     }
 117  
 
 118  
     public void setEndTimeAmPm(String endTimeAmPm) {
 119  0
         this.endTimeAmPm = endTimeAmPm;
 120  0
     }
 121  
 
 122  
     public boolean isAllDay() {
 123  0
         return allDay;
 124  
     }
 125  
 
 126  
     public void setAllDay(boolean allDay) {
 127  0
         this.allDay = allDay;
 128  0
     }
 129  
 
 130  
     public boolean isDateRange() {
 131  0
         return dateRange;
 132  
     }
 133  
 
 134  
     public void setDateRange(boolean dateRange) {
 135  0
         this.dateRange = dateRange;
 136  0
     }
 137  
 
 138  
     //This is for UI display purpose
 139  
     protected String formatStartDateUI(Date startDate){
 140  0
         if (startDate != null) {
 141  0
             if (!isAllDay()){
 142  0
                 SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm aa");
 143  0
                 String formattedDate = formatter.format(startDate);
 144  0
                 if (StringUtils.endsWithIgnoreCase(formattedDate,"12:00 am")){
 145  0
                     return StringUtils.removeEndIgnoreCase(formattedDate,"12:00 am");
 146  
                 }else {
 147  0
                     return formattedDate;
 148  
                 }
 149  
             }else{
 150  0
                 SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
 151  0
                 return formatter.format(startDate);
 152  
             }
 153  
         }else{
 154  0
             return StringUtils.EMPTY;
 155  
         }
 156  
 
 157  
     }
 158  
 
 159  
     //This is for UI display purpose
 160  
     protected String formatEndDateUI(Date endDate){
 161  0
         if (endDate != null) {
 162  0
             if (!isAllDay()){
 163  0
                 SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm aa");
 164  0
                 String formattedDate = formatter.format(endDate);
 165  0
                 if (StringUtils.endsWithIgnoreCase(formattedDate,"11:59 pm")){
 166  0
                     return StringUtils.removeEndIgnoreCase(formattedDate,"11:59 pm");
 167  
                 }else {
 168  0
                     return formattedDate;
 169  
                 }
 170  
             }else{
 171  0
                 SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
 172  0
                 return formatter.format(endDate);
 173  
             }
 174  
         }else{
 175  0
             return StringUtils.EMPTY;
 176  
         }
 177  
 
 178  
     }
 179  
 
 180  
 }