View Javadoc

1   /*
2    * This file is part of Domingo
3    * an Open Source Java-API to Lotus Notes/Domino
4    * hosted at http://domingo.sourceforge.net
5    *
6    * Copyright (c) 2003-2007 Beck et al. projects GmbH Munich, Germany (http://www.bea.de)
7    *
8    * This library is free software; you can redistribute it and/or
9    * modify it under the terms of the GNU Lesser General Public
10   * License as published by the Free Software Foundation; either
11   * version 2.1 of the License, or (at your option) any later version.
12   *
13   * This library is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   * Lesser General Public License for more details.
17   *
18   * You should have received a copy of the GNU Lesser General Public
19   * License along with this library; if not, write to the Free Software
20   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21   */
22  package de.bea.domingo.util;
23  
24  import java.util.Calendar;
25  
26  import de.bea.domingo.DDateRange;
27  
28  
29  /***
30   * A date/time range.
31   *
32   * @author <a href=mailto:kriede@users.sourceforge.net>Kurt Riede</a>
33   */
34  public final class GregorianDateTimeRange implements DDateRange {
35  
36      private GregorianDateTime fStart;
37  
38      private GregorianDateTime fEnd;
39  
40      /***
41       * Constructor.
42       */
43      public GregorianDateTimeRange() {
44      }
45  
46      /***
47       * Constructor.
48       *
49       * @param start start date
50       * @param end end date
51       */
52      public GregorianDateTimeRange(final Calendar start, final Calendar end) {
53          setFrom(start);
54          setTo(end);
55      }
56  
57      /***
58       * Returns the end date of the date range.
59       *
60       * @return start date
61       */
62      public Calendar getFrom() {
63          return fStart;
64      }
65  
66      /***
67       * Returns the end date of the date range.
68       *
69       * @return end date
70       */
71      public Calendar getTo() {
72          return fEnd;
73      }
74  
75      /***
76       * Sets the end date of the date range.
77       *
78       * @param end end date
79       */
80      public void setTo(final Calendar end) {
81          if (end instanceof GregorianDateTime) {
82              fEnd = (GregorianDateTime) end;
83          } else {
84              fEnd = new GregorianDateTime(end);
85          }
86      }
87  
88      /***
89       * Sets the end date of the date range.
90       *
91       * @param start start date
92       */
93      public void setFrom(final Calendar start) {
94          if (start instanceof GregorianDateTime) {
95              fStart = (GregorianDateTime) start;
96          } else {
97              fStart = new GregorianDateTime(start);
98          }
99      }
100 
101     /***
102      * {@inheritDoc}
103      * @see java.util.Calendar#toString()
104      */
105     public String toString() {
106         return DateUtil.getDateTimeString(getFrom()) + " - " + DateUtil.getDateTimeString(getTo());
107     }
108 }