Loading...
Searching...
No Matches
TimeInstant.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/TimeInstant.h
22
23 \brief A class to represent time instant.
24*/
25
26#ifndef __TERRALIB_DATATYPE_INTERNAL_TIMEINSTANT_H
27#define __TERRALIB_DATATYPE_INTERNAL_TIMEINSTANT_H
28
29// TerraLib
30#include "DateTimeInstant.h"
31#include "Date.h"
32#include "TimeDuration.h"
33
34// Boost
35#include <boost/date_time/posix_time/posix_time.hpp>
36
37namespace te
38{
39 namespace dt
40 {
41 class Date;
42
43 /*!
44 \class TimeInstant
45
46 \brief A class to represent time instant.
47
48 A time instant is a point on the continuous time axis. It is composed
49 of a date that uses the Gregorian calendar and of a local time.
50 Internally, it uses the datetime boost library to represent time instant,
51 by using the data type boost::posix_time::ptime.
52
53 \sa Date, DateTime, TimeInstantTZ, TimeDuration, TimePeriod, TimePeriodTZ, DatePeriod, DateDuration
54 */
56 {
57 public:
58
59 /*! \brief Constructor. */
61
62 /*!
63 \brief Constructor from a date and time offset.
64
65 \param d The date.
66 \param td Time offset.
67 */
68 TimeInstant(const Date& d, const TimeDuration& td);
69
70 /*!
71 \brief Constructor.
72
73 \param t A time instant.
74 */
75 TimeInstant(const boost::posix_time::ptime& t);
76
77 /*!
78 \brief Constructor.
79
80 It constructs a time instant from a non delimited ISO form string.
81 Example: 20020131T235959
82
83 \param dtime ISO form string
84 */
85 TimeInstant(const std::string& dtime);
86
87 /*!
88 \brief It returns the boost time instant type.
89
90 \return The boost time instant type.
91 */
92 const boost::posix_time::ptime& getTimeInstant() const { return m_timeInstant; }
93
94 /*!
95 \brief It returns the boost time instant type.
96
97 \return The boost time instant type.
98 */
99 boost::posix_time::ptime& getTimeInstant() { return m_timeInstant; }
100
101 /*!
102 \brief It returns the date associated to time instant.
103
104 \return The date
105 */
106 Date getDate() const { return Date(m_timeInstant.date()); }
107
108 /*!
109 \brief It returns the time duration associated to time instant.
110
111 \return The time duration
112 */
114
115 /*!
116 \brief Operator ==
117
118 \param rhs The time instant to be compared.
119
120 \return It returns true if the two time instants are equal. Otherwise, it returns false.
121 */
122 bool operator==(const DateTime& rhs) const;
123
124 /*!
125 \brief Operator !=
126
127 \param rhs The time instant to be compared.
128
129 \return It returns true if the two time instants are not equal. Otherwise, it returns false.
130 */
131 bool operator!=(const DateTime& rhs) const;
132
133 /*!
134 \brief Operator <
135
136 \param rhs The right-hand-side time instant to be compared.
137
138 \return It returns true if the right-hand-side time instant is greater than the lefth side one. Otherwise, it returns false.
139 */
140 bool operator<(const DateTime& rhs) const;
141
142 /*!
143 \brief Operator >
144
145 \param rhs The right-hand-side time instant to be compared.
146
147 \return It returns true if the right-hand-side time instant is less than the lefth side one. Otherwise, it returns false.
148 */
149 bool operator>(const DateTime& rhs) const;
150
151 /*!
152 \brief Operator -
153
154 \param rhs The right-hand-side time instant.
155
156 \return It returns the number of seconds between the two time instants.
157 */
158 long operator-(const TimeInstant& rhs) const;
159
160 /*!
161 \brief It returns a clone of this object.
162
163 \return A clone of this object.
164 */
166
167 /*!
168 \brief It returns the time instant in the ISO textual format (YYYYMMDDTHHMMSS,fffffffff) where T is the date-time separator.
169
170 \return The time instant in the ISO textual format (YYYYMMDDTHHMMSS,fffffffff) where T is the date-time separator.
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 */
180
181 /*! \brief Constructor. */
182 virtual ~TimeInstant();
183
184 //!< Returns an instance of this class initialized with the current date time
185 static TimeInstant* now();
186
187 protected:
188
189 boost::posix_time::ptime m_timeInstant; //!< The internal time instant information.
190 };
191
192 } // end namespace dt
193} // end namespace te
194
195#endif // __TERRALIB_DATATYPE_INTERNAL_TIMEINSTANT_H
196
An abstract class to represent an instant of date and time.
A base class for date data types.
A class to represent time duration.
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
A class to represent time duration with nano-second/micro-second resolution.
Definition: TimeDuration.h:52
A class to represent time instant.
Definition: TimeInstant.h:56
bool operator>(const DateTime &rhs) const
Operator >
boost::posix_time::ptime & getTimeInstant()
It returns the boost time instant type.
Definition: TimeInstant.h:99
bool operator==(const DateTime &rhs) const
Operator ==.
TimeInstant(const std::string &dtime)
Constructor.
static TimeInstant * now()
bool operator!=(const DateTime &rhs) const
Operator !=.
const boost::posix_time::ptime & getTimeInstant() const
It returns the boost time instant type.
Definition: TimeInstant.h:92
virtual ~TimeInstant()
Constructor.
long operator-(const TimeInstant &rhs) const
Operator -.
Date getDate() const
It returns the date associated to time instant.
Definition: TimeInstant.h:106
boost::posix_time::ptime m_timeInstant
The internal time instant information.
Definition: TimeInstant.h:189
std::string toString() const
It returns the time instant in the ISO textual format (YYYYMMDDTHHMMSS,fffffffff) where T is the date...
bool operator<(const DateTime &rhs) const
Operator <.
TimeDuration getTime() const
It returns the time duration associated to time instant.
TimeInstant()
Constructor.
TimeInstant(const boost::posix_time::ptime &t)
Constructor.
DateTimeType getDateTimeType() const
It returns the subtype of the date and time type.
Definition: TimeInstant.h:179
TimeInstant(const Date &d, const TimeDuration &td)
Constructor from a date and time offset.
AbstractData * clone() const
It returns a clone of this object.
DateTimeType
The subtype of date and time type, based on ISO 8621.
Definition: Enums.h:46
@ TIME_INSTANT
Definition: Enums.h:51
TerraLib.
#define TEDATATYPEEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:61