-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDate.cpp
More file actions
91 lines (77 loc) · 1.4 KB
/
Date.cpp
File metadata and controls
91 lines (77 loc) · 1.4 KB
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
82
83
84
85
86
87
88
89
90
#include "Date.h"
Date::Date(int d, int m, int y)
{
day = d;
month = m;
year = y;
}
int Date::getDay() const
{
return day;
}
int Date::getMonth() const
{
return month;
}
int Date::getYear() const
{
return year;
}
void Date::setDay(int d)
{
day = d;
}
void Date::setMonth(int m)
{
month = m;
}
void Date::setYear(int y)
{
year = y;
}
int Date::operator-(const Date& other) const
{
time_t thisTime = this->toTimeT();
time_t otherTime = other.toTimeT();
return difftime(thisTime, otherTime) / (60 * 60 * 24);
}
bool Date::operator<(const Date& other) const
{
if (year != other.year) {
return year < other.year;
}
if (month != other.month) {
return month < other.month;
}
return day < other.day;
}
bool Date::operator>(const Date& other) const {
return other < *this;
}
bool Date::operator<=(const Date& other) const
{
return !(*this > other);
}
bool Date::operator>=(const Date& other) const
{
return !(*this < other);
}
bool Date::operator==(const Date& other) const
{
return day == other.day && month == other.month && year == other.year;
}
bool Date::operator!=(const Date& other) const
{
return !(*this == other);
}
istream& operator>>(istream& is, Date& date)
{
char separator;
is >> date.day >> separator >> date.month >> separator >> date.year;
return is;
}
ostream& operator<<(ostream& os, const Date& date)
{
os << date.day << "/" << date.month << "/" << date.year;
return os;
}