1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.enrollment.class2.acal.util; |
17 | |
|
18 | |
import org.apache.commons.lang.time.DateFormatUtils; |
19 | |
import org.kuali.student.enrollment.class2.acal.dto.TimeSetWrapper; |
20 | |
import org.kuali.student.r2.common.dto.RichTextInfo; |
21 | |
|
22 | |
import java.text.SimpleDateFormat; |
23 | |
import java.util.Date; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | 0 | public class CommonUtils { |
31 | |
public static void assembleTimeSet(TimeSetWrapper timeSetWrapper, Date startDate, Date endDate) throws Exception{ |
32 | 0 | SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm aa"); |
33 | 0 | if (startDate !=null) { |
34 | 0 | String startDateFullString = formatter.format(startDate); |
35 | 0 | String[] timeStr = startDateFullString.split(" "); |
36 | 0 | timeSetWrapper.setStartDate(new SimpleDateFormat("MM/dd/yyyy").parse(timeStr[0])); |
37 | 0 | if (!"12:00".equals(timeStr[1])){ |
38 | 0 | timeSetWrapper.setStartTime(timeStr[1]); |
39 | |
} |
40 | 0 | timeSetWrapper.setStartTimeAmPm(timeStr[2].toLowerCase()); |
41 | |
} |
42 | |
|
43 | 0 | if (endDate !=null) { |
44 | 0 | String endDateFullString = formatter.format(endDate); |
45 | 0 | String[] timeStr = endDateFullString.split(" "); |
46 | 0 | timeSetWrapper.setEndDate(new SimpleDateFormat("MM/dd/yyyy").parse(timeStr[0])); |
47 | 0 | if (!"12:00".equals(timeStr[1])){ |
48 | 0 | timeSetWrapper.setEndTime(timeStr[1]); |
49 | |
} |
50 | 0 | timeSetWrapper.setEndTimeAmPm(timeStr[2].toLowerCase()); |
51 | |
|
52 | |
} |
53 | 0 | } |
54 | |
|
55 | |
public static boolean isValidDateRange(Date startDate,Date endDate){ |
56 | 0 | if(startDate != null && endDate != null) { |
57 | 0 | if (startDate.after(endDate) || endDate.before(startDate)){ |
58 | 0 | return false; |
59 | |
} |
60 | |
} |
61 | 0 | return true; |
62 | |
} |
63 | |
|
64 | |
public static String formatDate(Date date){ |
65 | 0 | return DateFormatUtils.format(date, CalendarConstants.DEFAULT_DATE_FORMAT); |
66 | |
} |
67 | |
|
68 | |
public static boolean isDateWithinRange(Date startDate,Date endDate,Date checkDate){ |
69 | 0 | if(startDate != null && endDate != null && checkDate != null) { |
70 | 0 | if (checkDate.before(startDate) || checkDate.after(endDate)){ |
71 | 0 | return false; |
72 | |
} |
73 | |
} |
74 | 0 | return true; |
75 | |
} |
76 | |
|
77 | |
public static RichTextInfo buildDesc(String descr){ |
78 | 0 | RichTextInfo rti = new RichTextInfo(); |
79 | 0 | rti.setPlain(descr); |
80 | 0 | return rti; |
81 | |
} |
82 | |
|
83 | |
public static Date getStartDate(TimeSetWrapper timeSetWrapper) throws Exception { |
84 | 0 | Date startDate = timeSetWrapper.getStartDate(); |
85 | 0 | String startTime = timeSetWrapper.getStartTime(); |
86 | 0 | String amPm = timeSetWrapper.getStartTimeAmPm(); |
87 | 0 | Date fullStartDate = getDate(startDate, startTime, amPm); |
88 | |
|
89 | 0 | return fullStartDate; |
90 | |
} |
91 | |
|
92 | |
public static Date getEndDate(TimeSetWrapper timeSetWrapper) throws Exception { |
93 | 0 | Date endate = timeSetWrapper.getEndDate(); |
94 | 0 | String endTime = timeSetWrapper.getEndTime(); |
95 | 0 | String amPm = timeSetWrapper.getEndTimeAmPm(); |
96 | 0 | Date fullEndDate = getDate(endate, endTime, amPm); |
97 | |
|
98 | 0 | return fullEndDate; |
99 | |
} |
100 | |
|
101 | |
|
102 | |
public static Date getDate(Date adate, String atime, String ampm) throws Exception { |
103 | 0 | Date fullDate = null; |
104 | 0 | if (ampm == null) |
105 | 0 | ampm = "am"; |
106 | |
|
107 | 0 | if(adate != null){ |
108 | 0 | if(atime != null && !atime.isEmpty()){ |
109 | 0 | String fullDateString = new SimpleDateFormat("MM/dd/yyyy").format(adate); |
110 | 0 | fullDateString = fullDateString.concat(" " + atime + " " + ampm); |
111 | 0 | SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm aa"); |
112 | 0 | fullDate = formatter.parse(fullDateString); |
113 | 0 | } |
114 | |
else { |
115 | 0 | fullDate = adate; |
116 | |
} |
117 | |
} |
118 | |
|
119 | 0 | return fullDate; |
120 | |
|
121 | |
} |
122 | |
|
123 | |
} |