1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.kernel.cal;
16  
17  import com.liferay.portal.kernel.util.CalendarFactoryUtil;
18  import com.liferay.portal.kernel.util.Validator;
19  
20  import java.util.Calendar;
21  import java.util.TimeZone;
22  
23  /**
24   * <a href="TZSRecurrence.java.html"><b><i>View Source</i></b></a>
25   *
26   * @author Samuel Kong
27   */
28  public class TZSRecurrence extends Recurrence {
29  
30      public TZSRecurrence() {
31      }
32  
33      public TZSRecurrence(Calendar start, Duration duration) {
34          super(start, duration);
35      }
36  
37      public TZSRecurrence(Calendar start, Duration duration, int frequency) {
38          super(start, duration, frequency);
39      }
40  
41      public TimeZone getTimeZone() {
42          return _timeZone;
43      }
44  
45      public void setTimeZone(TimeZone timeZone) {
46          _timeZone = timeZone;
47      }
48  
49      protected boolean matchesByField(
50          int[] array, int field, Calendar candidate, boolean allowNegative,
51          TimeZone timeZone) {
52  
53          Calendar adjustedCandidate = candidate;
54  
55          if (Validator.isNotNull(timeZone)) {
56              adjustedCandidate = CalendarFactoryUtil.getCalendar(timeZone);
57  
58              adjustedCandidate.setTime(candidate.getTime());
59          }
60  
61          return matchesByField(array, field, adjustedCandidate, allowNegative);
62      }
63  
64      protected boolean matchesIndividualByDay(
65          Calendar candidate, DayAndPosition pos) {
66  
67          Calendar adjustedCandidate = candidate;
68  
69          if (Validator.isNotNull(_timeZone)) {
70              adjustedCandidate = CalendarFactoryUtil.getCalendar(_timeZone);
71  
72              adjustedCandidate.setTime(candidate.getTime());
73          }
74  
75          return super.matchesIndividualByDay(adjustedCandidate, pos);
76      }
77  
78      protected boolean matchesByMonthDay(Calendar candidate) {
79          return matchesByField(
80              byMonthDay, Calendar.DATE, candidate, true, _timeZone);
81      }
82  
83      protected boolean matchesByYearDay(Calendar candidate) {
84          return matchesByField(
85              byYearDay, Calendar.DAY_OF_YEAR, candidate, true, _timeZone);
86      }
87  
88      protected boolean matchesByWeekNo(Calendar candidate) {
89          return matchesByField(
90              byWeekNo, Calendar.WEEK_OF_YEAR, candidate, true, _timeZone);
91      }
92  
93      protected boolean matchesByMonth(Calendar candidate) {
94          return matchesByField(
95              byMonth, Calendar.MONTH, candidate, false, _timeZone);
96      }
97  
98      private TimeZone _timeZone;
99  
100 }