bpp-popgen  3.0.0
Date.cpp
Go to the documentation of this file.
1 //
2 // File Date.cpp
3 // Author : Sylvain Gaillard <yragael2001@yahoo.fr>
4 // Last modification : Thursday July 29 2004
5 //
6 
7 /*
8  Copyright or © or Copr. CNRS, (November 17, 2004)
9 
10  This software is a computer program whose purpose is to provide classes
11  for population genetics analysis.
12 
13  This software is governed by the CeCILL license under French law and
14  abiding by the rules of distribution of free software. You can use,
15  modify and/ or redistribute the software under the terms of the CeCILL
16  license as circulated by CEA, CNRS and INRIA at the following URL
17  "http://www.cecill.info".
18 
19  As a counterpart to the access to the source code and rights to copy,
20  modify and redistribute granted by the license, users are provided only
21  with a limited warranty and the software's author, the holder of the
22  economic rights, and the successive licensors have only limited
23  liability.
24 
25  In this respect, the user's attention is drawn to the risks associated
26  with loading, using, modifying and/or developing or reproducing the
27  software by the user in light of its specific status of free software,
28  that may mean that it is complicated to manipulate, and that also
29  therefore means that it is reserved for developers and experienced
30  professionals having in-depth computer knowledge. Users are therefore
31  encouraged to load and test the software's suitability as regards their
32  requirements in conditions enabling the security of their systems and/or
33  data to be ensured and, more generally, to use and operate it in the
34  same conditions as regards security.
35 
36  The fact that you are presently reading this means that you have had
37  knowledge of the CeCILL license and that you accept its terms.
38  */
39 
40 #include <Bpp/Text/TextTools.h>
41 
42 // From Local
43 #include "Date.h"
44 
45 using namespace bpp;
46 using namespace std;
47 
48 // ** Class constructor: *******************************************************/
49 
50 Date::Date(const int day, const int month, const int year) : day_(day),
51  month_(month),
52  year_(year)
53 {
54  if (day < 1 || day > 31)
55  throw (BadIntegerException("Date::Date: day must be in [1;31].", day));
56  if (month < 1 || month > 12)
57  throw (BadIntegerException("Date::Date: month must be in [1;12].", month));
58 }
59 
60 Date::Date(const Date& date) : day_(date.getDay()),
61  month_(date.getMonth()),
62  year_(date.getYear()) {}
63 
64 // ** Class destructor: ********************************************************/
65 
67 
68 // ** Other methodes: **********************************************************/
69 
70 Date& Date::operator=(const Date& date)
71 {
72  day_ = date.getDay();
73  month_ = date.getMonth();
74  year_ = date.getYear();
75  return *this;
76 }
77 
78 void Date::setDate(const int day, const int month, const int year)
79 {
80  if (day >= 1 && day <= 31)
81  day_ = day;
82  else
83  throw (BadIntegerException("Date::Date: day must be in [1;31].", day));
84  if (month >= 1 && month <= 12)
85  month_ = month;
86  else
87  throw (BadIntegerException("Date::Date: month must be in [1;12].", month));
88  year_ = year;
89 }
90 
91 void Date::setYear(const int year)
92 {
93  year_ = year;
94 }
95 
96 void Date::setMonth(const int month)
97 {
98  if (month >= 1 && month <= 12)
99  month_ = month;
100  else
101  throw (BadIntegerException("Date::Date: month must be in [1;12].", month));
102 }
103 
104 void Date::setDay(const int day)
105 {
106  if (day >= 1 && day <= 31)
107  day_ = day;
108  else
109  throw (BadIntegerException("Date::Date: day must be in [1;31].", day));
110 }
111 
112 std::string Date::getDateStr() const
113 {
114  string date, uDay = "", uMonth = "";
115  if (day_ < 10)
116  uDay = "0";
117  if (month_ < 10)
118  uMonth = "0";
120  return date;
121 }
122 
123 bool Date::operator==(const Date& date) const
124 {
125  if (day_ == date.getDay() && month_ == date.getMonth() && year_ == date.getYear())
126  return true;
127  else
128  return false;
129 }
130 
131 bool Date::operator<(const Date& date) const
132 {
133  if (year_ < date.getYear() || (month_ < date.getMonth() && year_ == date.getYear()) || (day_ < date.getDay() && month_ == date.getMonth() && year_ == date.getYear()))
134  return true;
135  else
136  return false;
137 }
138 
The Date class.
Definition: Date.h:57
std::string getDateStr() const
Get the Date as a string.
Definition: Date.cpp:112
int getMonth() const
Get the month as an int.
Definition: Date.h:141
void setYear(const int year)
Set the year.
Definition: Date.cpp:91
int getYear() const
Get the Year as an int.
Definition: Date.h:136
bool operator==(const Date &date) const
The == operator.
Definition: Date.cpp:123
void setDay(const int day)
Set the day.
Definition: Date.cpp:104
int year_
Definition: Date.h:61
Date(const int day=1, const int month=1, const int year=2000)
Build a new Date from three values.
Definition: Date.cpp:50
void setMonth(const int month)
Set the month.
Definition: Date.cpp:96
bool operator<(const Date &date) const
The < operator.
Definition: Date.cpp:131
Date & operator=(const Date &date)
The Date copy operator.
Definition: Date.cpp:70
~Date()
Destroy the Date object.
Definition: Date.cpp:66
void setDate(const int day, const int month, const int year)
Set the Date.
Definition: Date.cpp:78
int day_
Definition: Date.h:59
int getDay() const
Get the day as an int.
Definition: Date.h:146
int month_
Definition: Date.h:60
std::string toString(T t)