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 
37 namespace 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. */
60  TimeInstant();
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  */
113  TimeDuration getTime() const;
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  */
165  AbstractData* clone() const;
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  protected:
185 
186  boost::posix_time::ptime m_timeInstant; //!< The internal time instant information.
187  };
188 
189  } // end namespace dt
190 } // end namespace te
191 
192 #endif // __TERRALIB_DATATYPE_INTERNAL_TIMEINSTANT_H
193 
static te::dt::TimeDuration td(20, 30, 50, 11)
te::da::Expression * operator==(const te::da::Expression &e1, const te::da::Expression &e2)
boost::posix_time::ptime m_timeInstant
The internal time instant information.
Definition: TimeInstant.h:186
#define TEDATATYPEEXPORT
You can use this macro in order to export/import classes and functions from this module.
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: TimeInstant.h:179
const boost::posix_time::ptime & getTimeInstant() const
It returns the boost time instant type.
Definition: TimeInstant.h:92
A class to represent time instant.
Definition: TimeInstant.h:55
A class to represent time duration.
Date getDate() const
It returns the date associated to time instant.
Definition: TimeInstant.h:106
A base class for date data types.
Definition: Date.h:53
te::da::Expression * operator<(const te::da::Expression &e1, const te::da::Expression &e2)
URI C++ Library.
Definition: Attributes.h:37
static te::dt::DateTime d(2010, 8, 9, 15, 58, 39)
static te::dt::TimeDuration dt(20, 30, 50, 11)
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::posix_time::ptime & getTimeInstant()
It returns the boost time instant type.
Definition: TimeInstant.h:99
A class to represent time duration with nano-second/micro-second resolution.
Definition: TimeDuration.h:51
DateTimeType
The subtype of date and time type, based on ISO 8621.
An abstract class to represent an instant of date and time.
An abstract class to represent an instant of date and time.
A base class for date data types.