1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
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  /**
29   * <a href="TZSRecurrence.java.html"><b><i>View Source</i></b></a>
30   *
31   * @author Samuel Kong
32   *
33   */
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 }