DatePeriod.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/datatype/DatePeriod.h
22 
23  \brief A class to represent date period.
24 */
25 
26 #ifndef __TERRALIB_DATATYPE_INTERNAL_DATEPERIOD_H
27 #define __TERRALIB_DATATYPE_INTERNAL_DATEPERIOD_H
28 
29 // TerraLib
30 #include "DateTimePeriod.h"
31 
32 // Boost
33 #include <boost/date_time/gregorian/gregorian.hpp>
34 
35 namespace te
36 {
37  namespace dt
38  {
39  /*!
40  \class DatePeriod
41 
42  \brief A class to represent date period based on the Gregorian Calendar.
43 
44  A class to represent date period based on the Gregorian Calendar.
45  A date period represents a range between two dates. Internally,
46  it uses the datetime boost library to represent gregorian date period,
47  by using the data type boost::gregorian::date_period.
48 
49  \sa DateTime, Date, DateDuration, TimeDuration, TimeInstant, TimeInstantTZ, TimePeriod, TimePeriodTZ
50  */
52  {
53  public:
54 
55  /*! \brief Constructor. */
56  DatePeriod();
57 
58  /*!
59  \brief Constructor.
60 
61  \param initialDate An initial gregorian date.
62  \param finalDate An final gregorian date.
63  */
64  DatePeriod(const Date& initialDate, const Date& finalDate);
65 
66  /*!
67  \brief Constructor.
68 
69  \param dp A date period based on the Gregorian Calendar.
70  */
71  DatePeriod(const boost::gregorian::date_period& dp);
72 
73  /*!
74  \brief It creates a period as [begin, end).
75 
76  \param begin The initial date.
77  \param begin The final date.
78  */
79  DatePeriod(const boost::gregorian::date& begin, const boost::gregorian::date& end);
80 
81  /*!
82  \brief It returns the boost date period type.
83 
84  \return The boost date period type.
85  */
86  const boost::gregorian::date_period& getDatePeriod() const { return m_datePeriod; }
87 
88  /*!
89  \brief It returns the boost date period type.
90 
91  \return The boost date period type.
92  */
93  boost::gregorian::date_period& getDatePeriod() { return m_datePeriod; }
94 
95  /*!
96  \brief It gets the initial date.
97 
98  \return The initial date
99  */
100  Date getInitialDate() const;
101 
102  /*!
103  \brief It gets the final date.
104 
105  \return The final date
106  */
107  Date getFinalDate() const;
108 
109  /*!
110  \brief It gets the initial date time instant.
111 
112  \return The initial time instant
113 
114  \note The caller will take the ownership of the returned pointer.
115  */
116  DateTimeInstant* getInitialInstant() const;
117 
118  /*!
119  \brief It gets the final date time instant.
120 
121  \return The final time instant
122 
123  \note The caller will take the ownership of the returned pointer.
124  */
125  DateTimeInstant* getFinalInstant() const;
126 
127  /*!
128  \brief Operator ==
129 
130  \param rhs The date period to be compared.
131 
132  \return It returns true if the two date periods are equal. Otherwise, it returns false.
133  */
134  bool operator==(const DateTime& rhs) const;
135 
136  /*!
137  \brief Operator !=
138 
139  \param rhs The date period to be compared.
140 
141  \return It returns true if the two date periods are not equal. Otherwise, it returns false.
142  */
143  bool operator!=(const DateTime& rhs) const;
144 
145  /*!
146  \brief Operator <
147 
148  \param rhs The right side date period to be compared.
149 
150  \return It returns true if the right side date period is greater than the lefth side one. Otherwise, it returns false.
151  */
152  bool operator<(const DateTime& rhs) const;
153 
154  /*!
155  \brief Operator >
156 
157  \param rhs The right side date period to be compared.
158 
159  \return It returns true if the right side date period is less than the lefth side one. Otherwise, it returns false.
160  */
161  bool operator>(const DateTime& rhs) const;
162 
163  /*!
164  \brief It returns a clone of this object.
165 
166  \return A clone of this object.
167  */
168  AbstractData* clone() const;
169 
170  /*!
171  \brief It returns the date period in the ISO textual format (YYYYMMDDTYYYYMMDD).
172 
173  \return The date period in the ISO textual format (YYYYMMDDTYYYYMMDD).
174  */
175  std::string toString() const;
176 
177  /*!
178  \brief It returns the subtype of the date and time type.
179 
180  \return The subtype of the date and time type.
181  */
183 
184  /*!
185  \brief Destructor.
186  */
187  virtual ~DatePeriod();
188 
189  protected:
190 
191  boost::gregorian::date_period m_datePeriod; //!< The internal date period information.
192  };
193  } // end namespace dt
194 } // end namespace te
195 
196 #endif // __TERRALIB_DATATYPE_INTERNAL_DATEPERIOD_H
197 
TEDATAACCESSEXPORT te::da::Expression * operator<(const te::da::Expression &e1, const te::da::Expression &e2)
TEDATAACCESSEXPORT te::da::Expression * operator==(const te::da::Expression &e1, const te::da::Expression &e2)
TEDATAACCESSEXPORT te::da::Expression * operator!=(const te::da::Expression &e1, const te::da::Expression &e2)
#define TEDATATYPEEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:61
A base class for date data types.
Definition: Date.h:53
URI C++ Library.
TEDATAACCESSEXPORT te::da::Expression * operator>(const te::da::Expression &e1, const te::da::Expression &e2)
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
boost::gregorian::date_period m_datePeriod
The internal date period information.
Definition: DatePeriod.h:191
DateTimeType getDateTimeType() const
It returns the subtype of the date and time type.
Definition: DatePeriod.h:182
boost::gregorian::date_period & getDatePeriod()
It returns the boost date period type.
Definition: DatePeriod.h:93
An abstract class to represent a period of date and time.
const boost::gregorian::date_period & getDatePeriod() const
It returns the boost date period type.
Definition: DatePeriod.h:86
DateTimeType
The subtype of date and time type, based on ISO 8621.
Definition: Enums.h:45
A class to represent date period based on the Gregorian Calendar.
Definition: DatePeriod.h:51
An abstract class to represent a period of date and time.
An abstract class to represent an instant of date and time.