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