All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Date.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/Date.cpp
22 
23  \brief A base class for date data types.
24 */
25 
26 // TerraLib
27 #include "Date.h"
28 
30  : m_date()
31 {
32 }
33 
34 te::dt::Date::Date(boost::gregorian::greg_year year,
35  boost::gregorian::greg_month month,
36  boost::gregorian::greg_day day)
37  : m_date(year, month, day)
38 {
39 }
40 
41 te::dt::Date::Date(const boost::gregorian::date& d)
42  : m_date(d)
43 {
44 }
45 
46 bool te::dt::Date::operator==(const DateTime& rhs) const
47 {
48  const te::dt::Date* t = dynamic_cast<const te::dt::Date*>(&rhs);
49  return m_date == t->getDate();
50 }
51 
52 bool te::dt::Date::operator!=(const DateTime& rhs) const
53 {
54  const te::dt::Date* t = dynamic_cast<const te::dt::Date*>(&rhs);
55  return m_date != t->getDate();
56 }
57 
58 bool te::dt::Date::operator<(const DateTime& rhs) const
59 {
60  const te::dt::Date* t = dynamic_cast<const te::dt::Date*>(&rhs);
61  return m_date < t->getDate();
62 }
63 
64 bool te::dt::Date::operator>(const DateTime& rhs) const
65 {
66  const te::dt::Date* t = dynamic_cast<const te::dt::Date*>(&rhs);
67  return m_date > t->getDate();
68 }
69 
70 long te::dt::Date::operator-(const Date& rhs) const
71 {
72  boost::gregorian::date_duration dd(m_date - rhs.getDate());
73 
74  return dd.days();
75 }
76 
78 {
79  return new Date(*this);
80 }
81 
82 std::string te::dt::Date::toString() const
83 {
84  return boost::gregorian::to_simple_string(m_date);
85  //return boost::gregorian::to_iso_extended_string(m_date);
86  //return boost::gregorian::to_iso_string(m_date);
87 }
88 
90 {
91 }
92 
93 
Date()
Empty constructor.
Definition: Date.cpp:29
bool operator<(const DateTime &rhs) const
Operator <.
Definition: Date.cpp:58
std::string toString() const
It returns the date in the ISO textual format (YYYYMMDD).
Definition: Date.cpp:82
bool operator>(const DateTime &rhs) const
Operator >
Definition: Date.cpp:64
AbstractData * clone() const
It returns a clone of this object.
Definition: Date.cpp:77
virtual ~Date()
Destructor.
Definition: Date.cpp:89
const boost::gregorian::date & getDate() const
It returns the internal boost date type.
Definition: Date.h:83
A base class for date data types.
Definition: Date.h:53
bool operator!=(const DateTime &rhs) const
Operator !=.
Definition: Date.cpp:52
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
bool operator==(const DateTime &rhs) const
Operator ==.
Definition: Date.cpp:46
long operator-(const Date &rhs) const
Operator -.
Definition: Date.cpp:70
A base class for date data types.