Date.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/Date.h
22 
23  \brief A base class for date data types.
24 */
25 
26 #ifndef __TERRALIB_DATATYPE_INTERNAL_DATE_H
27 #define __TERRALIB_DATATYPE_INTERNAL_DATE_H
28 
29 // TerraLib
30 #include "DateTimeInstant.h"
31 
32 // Boost
33 #include <boost/date_time/gregorian/gregorian.hpp>
34 
35 namespace te
36 {
37  namespace dt
38  {
39  /*!
40  \class Date
41 
42  \brief A base class for date data types.
43 
44  A class to represent dates based on the Gregorian Calendar. Internally,
45  it uses boost datetime library to represent gregorian date, by using
46  the data type boost::gregorian::date. For more information see the date
47  representation defined in ISO 8601:2004 specification.
48 
49  \ingroup datatype
50 
51  \sa DateTime, DateDuration, DatePeriod, TimeDuration, TimeInstant, TimeInstantTZ, TimePeriod, TimePeriodTZ
52  */
54  {
55  public:
56 
57  /*! \brief Empty constructor. */
58  Date();
59 
60  /*!
61  \brief Constructor.
62 
63  \param year A gregorian year in the range: [1400, 9999].
64  \param month A gregorian month in the range: [1, 12].
65  \param day A gregorian day in the range: [1,31].
66  */
67  Date(boost::gregorian::greg_year year,
68  boost::gregorian::greg_month month,
69  boost::gregorian::greg_day day);
70 
71  /*!
72  \brief Constructor.
73 
74  \param d A date based on the Gregorian Calendar.
75  */
76  Date(const boost::gregorian::date& d);
77 
78  /*!
79  \brief It returns the internal boost date type.
80 
81  \return The internal boost date type.
82  */
83  const boost::gregorian::date& getDate() const { return m_date; }
84 
85  /*!
86  \brief It returns the internal boost date type.
87 
88  \return The internal boost date type.
89  */
90  boost::gregorian::date& getDate() { return m_date; }
91 
92  /*!
93  \brief It returns the gregorian day - from 1 to 31.
94 
95  \return The gregorian day.
96  */
97  boost::gregorian::greg_day getDay() const { return m_date.day(); }
98 
99  /*!
100  \brief It returns the gregorian month - from 1 to 12.
101 
102  \return The gregorian month.
103  */
104  boost::gregorian::greg_month getMonth() const { return m_date.month(); }
105 
106  /*!
107  \brief It returns the gregorian year.
108 
109  \return The gregorian year.
110  */
111  boost::gregorian::greg_year getYear() const { return m_date.year(); }
112 
113  /*!
114  \brief Operator ==
115 
116  \param rhs The date to be compared.
117 
118  \return It returns true if the two dates are equal. Otherwise, it returns false.
119  */
120  bool operator==(const DateTime& rhs) const;
121 
122  /*!
123  \brief Operator !=
124 
125  \param rhs The date to be compared.
126 
127  \return It returns true if the two dates are not equal. Otherwise, it returns false.
128  */
129  bool operator!=(const DateTime& rhs) const;
130 
131  /*!
132  \brief Operator <
133 
134  \param rhs The right side date to be compared.
135 
136  \return It returns true if the right side date is greater than the lefth side one. Otherwise, it returns false.
137  */
138  bool operator<(const DateTime& rhs) const;
139 
140  /*!
141  \brief Operator >
142 
143  \param rhs The right side date to be compared.
144 
145  \return It returns true if the right side date is less than the lefth side one. Otherwise, it returns false.
146  */
147  bool operator>(const DateTime& rhs) const;
148 
149  /*!
150  \brief Operator -
151 
152  \param rhs The right side datetime.
153 
154  \return It returns the number of the days between two dates.
155 
156  \todo This operator must return DateDuration instead of long!
157  */
158  long operator-(const Date& rhs) const;
159 
160  /*!
161  \brief It returns a clone of this object.
162 
163  \return A clone of this object.
164  */
165  AbstractData* clone() const;
166 
167  /*!
168  \brief It returns the date in the ISO textual format (YYYYMMDD).
169 
170  \return The date in the ISO textual format (YYYYMMDD).
171  */
172  std::string toString() const;
173 
174  /*!
175  \brief It returns the subtype of the date and time type.
176 
177  \return The subtype of the date and time type.
178  */
179  DateTimeType getDateTimeType() const { return DATE; }
180 
181  /*!
182  \brief Destructor.
183  */
184  virtual ~Date();
185 
186  protected:
187 
188  boost::gregorian::date m_date; //!< Internal date information.
189  };
190 
191  } // end namespace dt
192 } // end namespace te
193 
194 #endif // __TERRALIB_DATATYPE_INTERNAL_DATE_H
195 
TEDATAACCESSEXPORT te::da::Expression * operator<(const te::da::Expression &e1, const te::da::Expression &e2)
boost::gregorian::date m_date
Internal date information.
Definition: Date.h:188
boost::gregorian::greg_year getYear() const
It returns the gregorian year.
Definition: Date.h:111
boost::gregorian::greg_day getDay() const
It returns the gregorian day - from 1 to 31.
Definition: Date.h:97
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)
DateTimeType getDateTimeType() const
It returns the subtype of the date and time type.
Definition: Date.h:179
#define TEDATATYPEEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:61
const boost::gregorian::date & getDate() const
It returns the internal boost date type.
Definition: Date.h:83
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
DateTimeType
The subtype of date and time type, based on ISO 8621.
Definition: Enums.h:45
boost::gregorian::date & getDate()
It returns the internal boost date type.
Definition: Date.h:90
boost::gregorian::greg_month getMonth() const
It returns the gregorian month - from 1 to 12.
Definition: Date.h:104
An abstract class to represent an instant of date and time.
An abstract class to represent an instant of date and time.