All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TimePeriod.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/TimePeriod.cpp
22 
23  \brief A class to represent time period.
24 */
25 
26 // TerraLib
27 #include "TimePeriod.h"
28 #include "TimeInstant.h"
29 
31  : m_timePeriod(boost::posix_time::ptime(), boost::posix_time::ptime())
32 {
33 }
34 
35 te::dt::TimePeriod::TimePeriod(const TimeInstant& initialTime, const TimeInstant& finalTime)
36  : m_timePeriod(initialTime.getTimeInstant(), finalTime.getTimeInstant())
37 {
38 }
39 
40 te::dt::TimePeriod::TimePeriod(const boost::posix_time::time_period& t)
41  : m_timePeriod(t)
42 {
43 }
44 
46 {
47  return TimeInstant(m_timePeriod.begin());
48 }
49 
51 {
52  return TimeInstant(m_timePeriod.end());
53 }
54 
56 {
57  return new TimeInstant(m_timePeriod.begin());
58 }
59 
61 {
62  return new TimeInstant(m_timePeriod.end());
63 }
64 
66 {
67  const te::dt::TimePeriod* t = dynamic_cast<const te::dt::TimePeriod*>(&rhs);
68  return m_timePeriod == t->m_timePeriod;
69 }
70 
72 {
73  const te::dt::TimePeriod* t = dynamic_cast<const te::dt::TimePeriod*>(&rhs);
74  return m_timePeriod != t->m_timePeriod;
75 }
76 
78 {
79  const te::dt::TimePeriod* t = dynamic_cast<const te::dt::TimePeriod*>(&rhs);
80  return m_timePeriod < t->m_timePeriod;
81 }
82 
84 {
85  const te::dt::TimePeriod* t = dynamic_cast<const te::dt::TimePeriod*>(&rhs);
86  return m_timePeriod > t->m_timePeriod;
87 }
88 
90 {
91  return new te::dt::TimePeriod(*this);
92 }
93 
94 std::string te::dt::TimePeriod::toString() const
95 {
96  std::string begin(boost::posix_time::to_simple_string(m_timePeriod.begin()));
97  std::string end(boost::posix_time::to_simple_string(m_timePeriod.end()));
98  //std::string begin(boost::posix_time::to_iso_extended_string(m_timePeriod.begin()));
99  //std::string end(boost::posix_time::to_iso_extended_string(m_timePeriod.end()));
100  //std::string begin(boost::posix_time::to_iso_string(m_timePeriod.begin()));
101  //std::string end(boost::posix_time::to_iso_string(m_timePeriod.end()));
102  return std::string(begin + "/" + end);
103 }
104 
106 {
107 }
108 
109 
bool operator==(const DateTime &rhs) const
Operator ==.
Definition: TimePeriod.cpp:65
bool operator!=(const DateTime &rhs) const
Operator !=.
Definition: TimePeriod.cpp:71
A class to represent time instant.
Definition: TimeInstant.h:55
virtual ~TimePeriod()
Destructor.
Definition: TimePeriod.cpp:105
TimeInstant getFinalTimeInstant() const
It gets the final time instant.
Definition: TimePeriod.cpp:50
A class to represent time period.
TimeInstant getInitialTimeInstant() const
It gets the initial time instant.
Definition: TimePeriod.cpp:45
A class to represent time instant.
AbstractData * clone() const
It returns a clone of this object.
Definition: TimePeriod.cpp:89
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
DateTimeInstant * getInitialInstant() const
It gets the initial date time instant.
Definition: TimePeriod.cpp:55
bool operator>(const DateTime &rhs) const
Operator >
Definition: TimePeriod.cpp:83
bool operator<(const DateTime &rhs) const
Operator <.
Definition: TimePeriod.cpp:77
TimePeriod()
Constructor.
Definition: TimePeriod.cpp:30
A class to represent time period.
Definition: TimePeriod.h:54
DateTimeInstant * getFinalInstant() const
It gets the final date time instant.
Definition: TimePeriod.cpp:60
boost::posix_time::time_period m_timePeriod
Time period information.
Definition: TimePeriod.h:191
std::string toString() const
It returns the time period in the ISO textual format (YYYYMMDDThhmmss/YYYYMMDDThhmmss).
Definition: TimePeriod.cpp:94
An abstract class to represent an instant of date and time.