All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TimeInstant.cpp
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.cpp
22 
23  \brief A class to represent time instant.
24 */
25 
26 // TerraLib
27 #include "TimeInstant.h"
28 
30  : m_timeInstant()
31 {
32 }
33 
35  : m_timeInstant(d.getDate(), td.getTimeDuration())
36 {
37 }
38 
39 te::dt::TimeInstant::TimeInstant(const boost::posix_time::ptime& t)
40  : m_timeInstant(t)
41 {
42 }
43 
44 te::dt::TimeInstant::TimeInstant(const std::string& dtime)
45 {
46  m_timeInstant = boost::posix_time::from_iso_string(dtime);
47 }
48 
50 {
51  boost::posix_time::time_duration td = m_timeInstant.time_of_day();
52 
53  return te::dt::TimeDuration(td);
54 }
55 
57 {
58  const te::dt::TimeInstant* t = dynamic_cast<const te::dt::TimeInstant*>(&rhs);
59  return m_timeInstant == t->m_timeInstant;
60 }
61 
63 {
64  const te::dt::TimeInstant* t = dynamic_cast<const te::dt::TimeInstant*>(&rhs);
65  return m_timeInstant != t->m_timeInstant;
66 }
67 
69 {
70  const te::dt::TimeInstant* t = dynamic_cast<const te::dt::TimeInstant*>(&rhs);
71  return m_timeInstant < t->m_timeInstant;
72 }
73 
75 {
76  const te::dt::TimeInstant* t = dynamic_cast<const te::dt::TimeInstant*>(&rhs);
77  return m_timeInstant > t->m_timeInstant;
78 }
79 
81 {
82  boost::posix_time::time_duration td(m_timeInstant - rhs.m_timeInstant);
83 
84  return td.total_seconds();
85 }
86 
88 {
89  return new TimeInstant(*this);
90 }
91 
92 std::string te::dt::TimeInstant::toString() const
93 {
94  return boost::posix_time::to_simple_string(m_timeInstant);
95  //return boost::posix_time::to_iso_string(m_timeInstant);
96  //return boost::posix_time::to_iso_extended_string(m_timeInstant);
97 }
98 
100 {
101 }
102 
bool operator>(const DateTime &rhs) const
Operator >
Definition: TimeInstant.cpp:74
boost::posix_time::ptime m_timeInstant
The internal time instant information.
Definition: TimeInstant.h:186
bool operator!=(const DateTime &rhs) const
Operator !=.
Definition: TimeInstant.cpp:62
std::string toString() const
It returns the time instant in the ISO textual format (YYYYMMDDTHHMMSS,fffffffff) where T is the date...
Definition: TimeInstant.cpp:92
virtual ~TimeInstant()
Constructor.
Definition: TimeInstant.cpp:99
bool operator==(const DateTime &rhs) const
Operator ==.
Definition: TimeInstant.cpp:56
A class to represent time instant.
Definition: TimeInstant.h:55
AbstractData * clone() const
It returns a clone of this object.
Definition: TimeInstant.cpp:87
A base class for date data types.
Definition: Date.h:53
A class to represent time instant.
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
A class to represent time duration with nano-second/micro-second resolution.
Definition: TimeDuration.h:51
TimeDuration getTime() const
It returns the time duration associated to time instant.
Definition: TimeInstant.cpp:49
long operator-(const TimeInstant &rhs) const
Operator -.
Definition: TimeInstant.cpp:80
bool operator<(const DateTime &rhs) const
Operator <.
Definition: TimeInstant.cpp:68
TimeInstant()
Constructor.
Definition: TimeInstant.cpp:29