TimeDuration.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/TimeDuration.h
22 
23  \brief A class to represent time duration.
24 */
25 
26 #ifndef __TERRALIB_DATATYPE_INTERNAL_TIMEDURATION_H
27 #define __TERRALIB_DATATYPE_INTERNAL_TIMEDURATION_H
28 
29 // TerraLib
30 #include "DateTime.h"
31 
32 // Boost
33 #include <boost/cstdint.hpp>
34 #include <boost/date_time/posix_time/posix_time.hpp>
35 
36 namespace te
37 {
38  namespace dt
39  {
40  /*!
41  \class TimeDuration
42 
43  \brief A class to represent time duration with nano-second/micro-second resolution.
44 
45  A class to represent time duration with nano-second/micro-second resolution (hh:mm:ss,ss).
46  Internally, it uses the datetime boost library to represent time duration, by using
47  the data type boost::posix_time::time_duration.
48 
49  \sa DateTime, Date, DatePeriod, DateDuration, TimeInstant, TimeInstantTZ, TimePeriod, TimePeriodTZ
50  */
52  {
53  public:
54 
55  /*!
56  \brief Constructor.
57 
58  \param hours A number of hours of a day - from 0 to 23.
59  \param minutes A number of minutes of a hour - from 0 to 59.
60  \param seconds A number of seconds of a minute - from 0 to 59.
61  \param fracSeconds A fractional seconds.
62  */
63  TimeDuration(long hours, long minutes, long seconds, boost::int64_t fracSeconds = 0);
64 
65  /*!
66  \brief Constructor.
67 
68  \param t A time duration.
69  */
70  TimeDuration(boost::posix_time::time_duration& t);
71 
72  /*!
73  \brief It returns the boost time duration type.
74 
75  \return The boost time duration type.
76  */
77  const boost::posix_time::time_duration& getTimeDuration() const { return m_timeDuration; }
78 
79  /*!
80  \brief It returns the boost time duration type.
81 
82  \return The boost time duration type.
83  */
84  boost::posix_time::time_duration& getTimeDuration() { return m_timeDuration; }
85 
86  /*!
87  \brief It returns the hours of a day - from 0 to 23.
88 
89  \return The hour of a day.
90  */
91  long getHours() const { return m_timeDuration.hours(); }
92 
93  /*!
94  \brief It returns the minutes of a hour - from 0 to 59.
95 
96  \return The the minutes of a hour.
97  */
98  long getMinutes() const { return m_timeDuration.minutes(); }
99 
100  /*!
101  \brief It returns the seconds of a minute - from 0 to 59.
102 
103  \return The the seconds of a minute.
104  */
105  long getSeconds() const { return m_timeDuration.seconds(); }
106 
107  /*!
108  \brief It returns the fractional seconds
109 
110  \return The the fractional seconds
111  */
112  boost::int64_t getFractionalSeconds() const { return m_timeDuration.fractional_seconds(); }
113 
114  /*!
115  \brief Operator ==
116 
117  \param rhs The time duration to be compared.
118 
119  \return It returns true if the two time durations are equal. Otherwise, it returns false.
120  */
121  bool operator==(const DateTime& rhs) const;
122 
123  /*!
124  \brief Operator !=
125 
126  \param rhs The time duration to be compared.
127 
128  \return It returns true if the two time durations are not equal. Otherwise, it returns false.
129  */
130  bool operator!=(const DateTime& rhs) const;
131 
132  /*!
133  \brief Operator <
134 
135  \param rhs The right-hand-side time duration to be compared.
136 
137  \return It returns true if the right-hand-side time duration is greater than the lefth side one. Otherwise, it returns false.
138  */
139  bool operator<(const DateTime& rhs) const;
140 
141  /*!
142  \brief Operator <
143 
144  \param rhs The right-hand-side time duration to be compared.
145 
146  \return It returns true if the right-hand-side time duration is less than the lefth side one. Otherwise, it returns false.
147  */
148  bool operator>(const DateTime& rhs) const;
149 
150  /*!
151  \brief Operator -
152 
153  \param rhs The right-hand-side time instant.
154 
155  \return It returns the number of seconds between the two time durations.
156 
157  \todo This method should return time duration!
158  */
159  long operator-(const TimeDuration& rhs) const;
160 
161  /*!
162  \brief It returns a clone of this object.
163 
164  \return A clone of this object.
165  */
166  AbstractData* clone() const;
167 
168  /*!
169  \brief It returns the time duration in the ISO textual format (hh:mm:ss,ss).
170 
171  \return The date in the ISO textual format (hh:mm:ss,ss).
172  */
173  std::string toString() const;
174 
175  /*!
176  \brief It returns the subtype of the date and time type.
177 
178  \return The subtype of the date and time type.
179  */
181 
182  /*!
183  \brief Destructor.
184  */
185  virtual ~TimeDuration();
186 
187  protected:
188 
189  boost::posix_time::time_duration m_timeDuration; //!< The internal time duration information.
190  };
191 
192  } // end namespace dt
193 } // end namespace te
194 
195 #endif // __TERRALIB_DATATYPE_INTERNAL_TIMEDURATION_H
196 
TEDATAACCESSEXPORT te::da::Expression * operator<(const te::da::Expression &e1, const te::da::Expression &e2)
boost::posix_time::time_duration m_timeDuration
The internal time duration information.
Definition: TimeDuration.h:189
An abstract class for date and time types.
long getSeconds() const
It returns the seconds of a minute - from 0 to 59.
Definition: TimeDuration.h:105
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)
boost::posix_time::time_duration & getTimeDuration()
It returns the boost time duration type.
Definition: TimeDuration.h:84
#define TEDATATYPEEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:61
URI C++ Library.
boost::int64_t getFractionalSeconds() const
It returns the fractional seconds.
Definition: TimeDuration.h:112
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 getDateTimeType() const
It returns the subtype of the date and time type.
Definition: TimeDuration.h:180
const boost::posix_time::time_duration & getTimeDuration() const
It returns the boost time duration type.
Definition: TimeDuration.h:77
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.
Definition: Enums.h:45
long getMinutes() const
It returns the minutes of a hour - from 0 to 59.
Definition: TimeDuration.h:98
long getHours() const
It returns the hours of a day - from 0 to 23.
Definition: TimeDuration.h:91