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