-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDate.cpp
81 lines (62 loc) · 1.86 KB
/
Date.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <bits/stdc++.h>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <time.h>
#include "Date.h"
using namespace std;
Date::Date(int day, int month, int year) {
//there is no need for any validations since the Date Class
//will not be used by users
setMonth(month);
setDay(day);
setYear(year);
}
void Date::setDay(int Day) {
day = Day;
}
void Date::setMonth(int Month) {
month = Month;
}
void Date::setYear(int Year) {
year = Year;
}
int Date::getDay() {
return day;
}
int Date::getMonth() {
return month;
}
int Date::getYear() {
return year;
}
bool Date::operator < (Date date) {
if (this->year < date.getYear()) return true;
else if (this->year == date.getYear() and this->month < date.getMonth()) return true;
else if (this->year == date.getYear() and this->month == date.getMonth() and this->day < date.getDay()) return true;
return false;
}
bool Date::operator == (Date date) {
if (this->year == date.getYear() and this->month == date.getMonth() and this->day == date.getDay()) return true;
return false;
}
bool Date::operator > (Date date) {
if (this->year > date.getYear()) return true;
else if (this->year == date.getYear() and this->month > date.getMonth()) return true;
else if (this->year == date.getYear() and this->month == date.getMonth() and this->day > date.getDay()) return true;
return false;
}
Date Date::operator + (int Days) {
//this operator sums days to a date
short unsigned int Year = year, Month = month, Day = day;
boost::gregorian::date dateObj {Year, Month, Day};
boost::gregorian::days daysObj (Days);
dateObj += daysObj;
Date result(dateObj.day(), dateObj.month(), dateObj.year());
return result;
}
Date getCurrentDate() {
time_t now = time(0);
struct tm timeStruct;
timeStruct = *localtime(&now);
Date date(timeStruct.tm_mday, timeStruct.tm_mon+1, timeStruct.tm_year+1900);
return date;
}