001
014
015 package com.liferay.portal.kernel.cal;
016
017 import com.liferay.portal.kernel.util.CalendarFactoryUtil;
018 import com.liferay.portal.kernel.util.Validator;
019
020 import java.util.Calendar;
021 import java.util.TimeZone;
022
023
026 public class TZSRecurrence extends Recurrence {
027
028 public TZSRecurrence() {
029 }
030
031 public TZSRecurrence(Calendar start, Duration duration) {
032 super(start, duration);
033 }
034
035 public TZSRecurrence(Calendar start, Duration duration, int frequency) {
036 super(start, duration, frequency);
037 }
038
039 public TimeZone getTimeZone() {
040 return _timeZone;
041 }
042
043 public void setTimeZone(TimeZone timeZone) {
044 _timeZone = timeZone;
045 }
046
047 protected boolean matchesByField(
048 int[] array, int field, Calendar candidate, boolean allowNegative,
049 TimeZone timeZone) {
050
051 Calendar adjustedCandidate = candidate;
052
053 if (Validator.isNotNull(timeZone)) {
054 adjustedCandidate = CalendarFactoryUtil.getCalendar(timeZone);
055
056 adjustedCandidate.setTime(candidate.getTime());
057 }
058
059 return matchesByField(array, field, adjustedCandidate, allowNegative);
060 }
061
062 @Override
063 protected boolean matchesIndividualByDay(
064 Calendar candidate, DayAndPosition pos) {
065
066 Calendar adjustedCandidate = candidate;
067
068 if (Validator.isNotNull(_timeZone)) {
069 adjustedCandidate = CalendarFactoryUtil.getCalendar(_timeZone);
070
071 adjustedCandidate.setTime(candidate.getTime());
072 }
073
074 return super.matchesIndividualByDay(adjustedCandidate, pos);
075 }
076
077 @Override
078 protected boolean matchesByMonthDay(Calendar candidate) {
079 return matchesByField(
080 byMonthDay, Calendar.DATE, candidate, true, _timeZone);
081 }
082
083 @Override
084 protected boolean matchesByYearDay(Calendar candidate) {
085 return matchesByField(
086 byYearDay, Calendar.DAY_OF_YEAR, candidate, true, _timeZone);
087 }
088
089 @Override
090 protected boolean matchesByWeekNo(Calendar candidate) {
091 return matchesByField(
092 byWeekNo, Calendar.WEEK_OF_YEAR, candidate, true, _timeZone);
093 }
094
095 @Override
096 protected boolean matchesByMonth(Calendar candidate) {
097 return matchesByField(
098 byMonth, Calendar.MONTH, candidate, false, _timeZone);
099 }
100
101 private TimeZone _timeZone;
102
103 }