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