1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.core.calendar;
17
18 import org.joda.time.DateTime;
19 import org.kuali.kpme.core.api.calendar.CalendarParentContract;
20 import org.kuali.kpme.core.api.calendar.entry.CalendarEntry;
21 import org.kuali.kpme.core.calendar.web.CalendarWeek;
22 import org.kuali.kpme.core.service.HrServiceLocator;
23
24 import java.io.Serializable;
25 import java.util.ArrayList;
26 import java.util.List;
27
28 public abstract class CalendarParent implements Serializable, CalendarParentContract {
29
30 private static final long serialVersionUID = 8840878349037013345L;
31 private List<CalendarWeek> weeks = new ArrayList<CalendarWeek>();
32 private CalendarEntry calendarEntry;
33 private DateTime beginDateTime;
34 private DateTime endDateTime;
35
36 public CalendarParent(CalendarEntry calendarEntry) {
37 this.calendarEntry = calendarEntry;
38 if (calendarEntry != null) {
39 this.beginDateTime = calendarEntry.getBeginPeriodLocalDateTime().toDateTime(HrServiceLocator.getTimezoneService().getUserTimezoneWithFallback());
40 this.endDateTime = calendarEntry.getEndPeriodLocalDateTime().toDateTime(HrServiceLocator.getTimezoneService().getUserTimezoneWithFallback());
41 }
42 }
43
44 protected CalendarParent() {
45 }
46
47
48 public DateTime getBeginDateTime() {
49 return beginDateTime;
50 }
51
52 public void setBeginDateTime(DateTime beginDateTime) {
53 this.beginDateTime = beginDateTime;
54 }
55
56 public DateTime getEndDateTime() {
57 return endDateTime;
58 }
59
60 public void setEndDateTime(DateTime endDateTime) {
61 this.endDateTime = endDateTime;
62 }
63
64 public CalendarEntry getCalendarEntry() {
65 return calendarEntry;
66 }
67
68 public void setCalendarEntry(CalendarEntry calendarEntry) {
69 this.calendarEntry = calendarEntry;
70 }
71
72 public List<CalendarWeek> getWeeks() {
73 return weeks;
74 }
75
76 public void setWeeks(List<CalendarWeek> weeks) {
77 this.weeks = weeks;
78 }
79
80
81
82
83
84
85
86
87 public String getCalendarTitle() {
88 StringBuilder sb = new StringBuilder();
89
90 if (getBeginDateTime().getMonthOfYear() == getEndDateTime().getMonthOfYear() ||
91 (getBeginDateTime().getMonthOfYear() != getEndDateTime().getMonthOfYear()
92 && getEndDateTime().getDayOfMonth() == 1 && getEndDateTime().getSecondOfDay() == 0)) {
93 sb.append(getBeginDateTime().toString("MMMM y"));
94 } else {
95 sb.append(getBeginDateTime().toString("MMM y"));
96 sb.append(" - ");
97 sb.append(getEndDateTime().toString("MMM y"));
98 }
99
100 return sb.toString();
101 }
102
103
104
105
106
107
108 public List<String> getCalendarDayHeadings() {
109 List<String> dayStrings = new ArrayList<String>(7);
110
111 int firstDay = 0 - getBeginDateTime().getDayOfWeek();
112 int lastDay = firstDay + 7;
113
114 if (getBeginDateTime().getMinuteOfDay() == 0) {
115
116 for (int i = firstDay; i < lastDay; i++) {
117 DateTime currDay = getBeginDateTime().plusDays(i);
118 dayStrings.add(currDay.toString("E"));
119 }
120 } else {
121
122 for (int i = firstDay; i < lastDay; i++) {
123 StringBuilder builder = new StringBuilder("");
124 DateTime currStart = getBeginDateTime().plusDays(i);
125 DateTime currEnd = getBeginDateTime().plusDays(i);
126
127 builder.append(currStart.toString("E HH:mm"));
128 builder.append(" - ");
129 builder.append(currEnd.toString("E HH:mm"));
130
131 dayStrings.add(builder.toString());
132 }
133 }
134
135 return dayStrings;
136 }
137
138 }