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 protected boolean matchesIndividualByDay(
063 Calendar candidate, DayAndPosition pos) {
064
065 Calendar adjustedCandidate = candidate;
066
067 if (Validator.isNotNull(_timeZone)) {
068 adjustedCandidate = CalendarFactoryUtil.getCalendar(_timeZone);
069
070 adjustedCandidate.setTime(candidate.getTime());
071 }
072
073 return super.matchesIndividualByDay(adjustedCandidate, pos);
074 }
075
076 protected boolean matchesByMonthDay(Calendar candidate) {
077 return matchesByField(
078 byMonthDay, Calendar.DATE, candidate, true, _timeZone);
079 }
080
081 protected boolean matchesByYearDay(Calendar candidate) {
082 return matchesByField(
083 byYearDay, Calendar.DAY_OF_YEAR, candidate, true, _timeZone);
084 }
085
086 protected boolean matchesByWeekNo(Calendar candidate) {
087 return matchesByField(
088 byWeekNo, Calendar.WEEK_OF_YEAR, candidate, true, _timeZone);
089 }
090
091 protected boolean matchesByMonth(Calendar candidate) {
092 return matchesByField(
093 byMonth, Calendar.MONTH, candidate, false, _timeZone);
094 }
095
096 private TimeZone _timeZone;
097
098 }