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.StringUtils;
19 import org.apache.commons.lang.time.DateFormatUtils;
20 import org.apache.log4j.Logger;
21 import org.joda.time.MutableDateTime;
22 import org.kuali.student.enrollment.class2.acal.dto.TimeSetWrapper;
23 import org.kuali.student.r2.common.dto.RichTextInfo;
24 import org.kuali.student.r2.common.util.date.DateFormatters;
25
26 import java.util.Date;
27 import java.util.HashMap;
28 import java.util.Map;
29
30
31
32
33
34
35 public class CommonUtils {
36 public static void assembleTimeSet(TimeSetWrapper timeSetWrapper, Date startDate, Date endDate) throws Exception{
37
38 if (startDate !=null) {
39 String startDateFullString = DateFormatters.MONTH_DAY_YEAR_TIME_DATE_FORMATTER.format(startDate);
40 String[] timeStr = startDateFullString.split(" ");
41 timeSetWrapper.setStartDate(DateFormatters.MONTH_DAY_YEAR_DATE_FORMATTER.parse(timeStr[0]));
42 if (!"12:00".equals(timeStr[1])){
43 timeSetWrapper.setStartTime(timeStr[1]);
44 }
45 timeSetWrapper.setStartTimeAmPm(timeStr[2].toLowerCase());
46 }
47
48 if (endDate !=null) {
49 String endDateFullString = DateFormatters.MONTH_DAY_YEAR_TIME_DATE_FORMATTER.format(endDate);
50 String[] timeStr = endDateFullString.split(" ");
51 timeSetWrapper.setEndDate(DateFormatters.MONTH_DAY_YEAR_DATE_FORMATTER.parse(timeStr[0]));
52 if (!"12:00".equals(timeStr[1])){
53 timeSetWrapper.setEndTime(timeStr[1]);
54 }
55 timeSetWrapper.setEndTimeAmPm(timeStr[2].toLowerCase());
56
57 }
58 }
59
60 public static boolean isValidDateRange(Date startDate,Date endDate){
61 if(startDate != null && endDate != null) {
62 if (startDate.after(endDate) || endDate.before(startDate)){
63 return false;
64 }
65 }
66 return true;
67 }
68
69 public static String formatDate(Date date){
70 return DateFormatUtils.format(date, CalendarConstants.DEFAULT_DATE_FORMAT);
71 }
72
73 public static boolean isDateWithinRange(Date startDate,Date endDate,Date checkDate){
74 if(startDate != null && endDate != null && checkDate != null) {
75 if ((!checkDate.equals(startDate) && checkDate.before(startDate)) || (!checkDate.equals(endDate) && checkDate.after(endDate))){
76 return false;
77 }
78 }
79 return true;
80 }
81
82
83
84
85
86
87
88
89
90
91
92
93 public static boolean doDatesOverlap(Date periodStartDate, Date periodEndDate, Date subStart, Date subEnd){
94 boolean bRet = false;
95
96 int compStart = subStart.compareTo(periodEndDate);
97 int compEnd = subEnd.compareTo(periodStartDate);
98 if (compStart <= 0 && compEnd >= 0) {
99 bRet = true;
100 }
101
102 return bRet;
103 }
104
105 public static RichTextInfo buildDesc(String descr){
106 RichTextInfo rti = new RichTextInfo();
107 rti.setPlain(descr);
108 return rti;
109 }
110
111 public static Date getDateWithTime(Date date, String hourMinute, String amPm) {
112 if (null == date) {
113 return null;
114 }
115
116 MutableDateTime dateTime = new MutableDateTime(date);
117
118 if (StringUtils.isNotBlank(hourMinute)) {
119 int hour = Integer.parseInt(StringUtils.substringBefore(hourMinute,":"));
120 if (StringUtils.equalsIgnoreCase(amPm,"PM")) {
121
122 if (hour < 12) {
123 hour += 12;
124 }
125 }
126 else
127 if (hour == 12) {
128 hour = 0;
129 }
130 dateTime.setTime(hour, Integer.parseInt(StringUtils.substringAfter(hourMinute,":")), 0, 0);
131 }
132
133 return dateTime.toDate();
134 }
135
136 public static String getAdminOrgNameById(String id){
137
138 String adminOrgName = null;
139 Map<String, String> allHcOrgs = new HashMap<String, String>();
140 allHcOrgs.put("102", "Registrar's Office");
141
142 if(allHcOrgs.containsKey(id)){
143 adminOrgName = allHcOrgs.get(id);
144 }
145
146 return adminOrgName;
147 }
148
149 public static void logDebugMsg(Logger logger, String message) {
150 if (logger.isDebugEnabled()){
151 logger.debug(message);
152 }
153 }
154 }