View Javadoc

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.r2.common.util.date.DateFormatters;
20  
21  import java.util.Date;
22  
23  /**
24   * This is the base class for all the wrappers deals with start/end times and all day and date range flags
25   *
26   * @author Kuali Student Team
27   */
28  public class TimeSetWrapper {
29      private Date startDate;
30      private Date endDate;
31      private String startTime;
32      private String startTimeAmPm;
33      private String endTime;
34      private String endTimeAmPm;
35      private boolean allDay;
36      private boolean dateRange;
37  
38      //This is needed for view purpose as we're setting the end date as null sothat it wont display in the ui
39      protected Date endDateUI;
40  
41      protected void buildDateAndTime(){
42  
43          //This is needed to display enddate for readonly view (not needed for edit mode).
44          endDateUI = getEndDate();
45  
46          // some defaults
47          setStartTimeAmPm("AM");
48          setEndTimeAmPm("AM");
49  
50          // If not all day, set start/end time in the wrapper
51          if (!isAllDay()){
52              if (getStartDate() != null){
53                  setStartTime(DateFormatters.HOUR_MINUTE_TIME_FORMATTER.format(getStartDate()));
54                  setStartTimeAmPm(DateFormatters.AM_PM_TIME_FORMATTER.format(getStartDate()));
55              }
56              if (getEndDate() != null){
57                  setEndTime(DateFormatters.HOUR_MINUTE_TIME_FORMATTER.format(getEndDate()));
58                  setEndTimeAmPm(DateFormatters.AM_PM_TIME_FORMATTER.format(getEndDate()));
59              }
60          } else if (!isDateRange()){
61                  setEndDate(null);
62                  setEndTime(null);
63          }
64      }
65  
66      public Date getStartDate() {
67          return startDate;
68      }
69  
70      public void setStartDate(Date startDate) {
71          this.startDate = startDate;
72      }
73  
74      public Date getEndDate() {
75          return endDate;
76      }
77  
78      public void setEndDate(Date endDate) {
79          this.endDate = endDate;
80      }
81  
82      public String getStartTime() {
83          return startTime;
84      }
85  
86      public void setStartTime(String startTime) {
87          this.startTime = startTime;
88      }
89  
90      public String getStartTimeAmPm() {
91          return startTimeAmPm;
92      }
93  
94      public void setStartTimeAmPm(String startTimeAmPm) {
95          this.startTimeAmPm = startTimeAmPm;
96      }
97  
98      public String getEndTime() {
99          return endTime;
100     }
101 
102     public void setEndTime(String endTime) {
103         this.endTime = endTime;
104     }
105 
106     public String getEndTimeAmPm() {
107         return endTimeAmPm;
108     }
109 
110     public void setEndTimeAmPm(String endTimeAmPm) {
111         this.endTimeAmPm = endTimeAmPm;
112     }
113 
114     public boolean isAllDay() {
115         return allDay;
116     }
117 
118     public void setAllDay(boolean allDay) {
119         this.allDay = allDay;
120     }
121 
122     public boolean isDateRange() {
123         return dateRange;
124     }
125 
126     public void setDateRange(boolean dateRange) {
127         this.dateRange = dateRange;
128     }
129 
130     //This is for UI display purpose
131     protected String formatStartDateUI(Date startDate){
132         if (startDate != null) {
133             if (!isAllDay()){
134                 String formattedDate = DateFormatters.MONTH_DAY_YEAR_TIME_DATE_FORMATTER.format(startDate);
135                 return StringUtils.removeEndIgnoreCase(formattedDate,"12:00 am");
136             }else{
137                 return DateFormatters.MONTH_DAY_YEAR_DATE_FORMATTER.format(startDate);
138             }
139         }else{
140             return StringUtils.EMPTY;
141         }
142 
143     }
144 
145     //This is for UI display purpose
146     protected String formatEndDateUI(Date endDate){
147         if (endDate != null) {
148             if (!isAllDay()){
149                 String formattedEndDate = DateFormatters.MONTH_DAY_YEAR_TIME_DATE_FORMATTER.format(endDate);
150                 String formattedStartDate = DateFormatters.MONTH_DAY_YEAR_TIME_DATE_FORMATTER.format(startDate);
151                 String strippedDate = StringUtils.removeStart(formattedEndDate,StringUtils.substringBefore(formattedStartDate," "));
152                 return StringUtils.removeEndIgnoreCase(strippedDate,"11:59 pm");
153             }else{
154                 if (isDateRange()){
155                     return DateFormatters.MONTH_DAY_YEAR_DATE_FORMATTER.format(endDate);
156                 }else{
157                     return StringUtils.EMPTY;
158                 }
159             }
160         }else{
161             return StringUtils.EMPTY;
162         }
163 
164     }
165 
166 }