1
19
20 package com.liferay.portal.kernel.cal;
21
22 import com.liferay.portal.kernel.util.CalendarFactoryUtil;
23 import com.liferay.portal.kernel.util.Validator;
24
25 import java.util.Calendar;
26 import java.util.TimeZone;
27
28
34 public class TZSRecurrence extends Recurrence {
35
36 public TZSRecurrence() {
37 }
38
39 public TZSRecurrence(Calendar start, Duration duration) {
40 super(start, duration);
41 }
42
43 public TZSRecurrence(Calendar start, Duration duration, int frequency) {
44 super(start, duration, frequency);
45 }
46
47 public TimeZone getTimeZone() {
48 return _timeZone;
49 }
50
51 public void setTimeZone(TimeZone timeZone) {
52 _timeZone = timeZone;
53 }
54
55 protected boolean matchesByField(
56 int[] array, int field, Calendar candidate, boolean allowNegative,
57 TimeZone timeZone) {
58
59 Calendar adjustedCandidate = candidate;
60
61 if (Validator.isNotNull(timeZone)) {
62 adjustedCandidate = CalendarFactoryUtil.getCalendar(timeZone);
63
64 adjustedCandidate.setTime(candidate.getTime());
65 }
66
67 return matchesByField(array, field, adjustedCandidate, allowNegative);
68 }
69
70 protected boolean matchesIndividualByDay(
71 Calendar candidate, DayAndPosition pos) {
72
73 Calendar adjustedCandidate = candidate;
74
75 if (Validator.isNotNull(_timeZone)) {
76 adjustedCandidate = CalendarFactoryUtil.getCalendar(_timeZone);
77
78 adjustedCandidate.setTime(candidate.getTime());
79 }
80
81 return super.matchesIndividualByDay(adjustedCandidate, pos);
82 }
83
84 protected boolean matchesByMonthDay(Calendar candidate) {
85 return matchesByField(
86 byMonthDay, Calendar.DATE, candidate, true, _timeZone);
87 }
88
89 protected boolean matchesByYearDay(Calendar candidate) {
90 return matchesByField(
91 byYearDay, Calendar.DAY_OF_YEAR, candidate, true, _timeZone);
92 }
93
94 protected boolean matchesByWeekNo(Calendar candidate) {
95 return matchesByField(
96 byWeekNo, Calendar.WEEK_OF_YEAR, candidate, true, _timeZone);
97 }
98
99 protected boolean matchesByMonth(Calendar candidate) {
100 return matchesByField(
101 byMonth, Calendar.MONTH, candidate, false, _timeZone);
102 }
103
104 private TimeZone _timeZone;
105
106 }