-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdate.cpp
More file actions
47 lines (34 loc) · 1.37 KB
/
date.cpp
File metadata and controls
47 lines (34 loc) · 1.37 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
#include "date.h"
#include <iomanip>
#include <tuple>
Date::Date(int year, int month, int day) : year(year), month(month), day(day) {}
int Date::GetYear() const {
return year;
}
int Date::GetMonth() const {
return month;
}
int Date::GetDay() const {
return day;
}
Date ParseDate(istream& in_stream) {
int year, month, day;
in_stream >> year;
in_stream.ignore(1);
in_stream >> month;
in_stream.ignore(1);
in_stream >> day;
return Date(year, month, day);
}
ostream& operator<<(ostream& out_stream, const Date& date) {
out_stream << setfill('0') << setw(4);
out_stream << date.GetYear() << '-' << setw(2);
out_stream << date.GetMonth() << '-' << setw(2);
return out_stream << date.GetDay();
}
bool Date::operator<(const Date& o) const { return tie(year, month, day) < tie(o.year, o.month, o.day); }
bool Date::operator<=(const Date& o) const { return tie(year, month, day) <= tie(o.year, o.month, o.day); }
bool Date::operator>(const Date& o) const { return tie(year, month, day) > tie(o.year, o.month, o.day); }
bool Date::operator>=(const Date& o) const { return tie(year, month, day) >= tie(o.year, o.month, o.day); }
bool Date::operator==(const Date& o) const { return tie(year, month, day) == tie(o.year, o.month, o.day); }
bool Date::operator!=(const Date& o) const { return tie(year, month, day) != tie(o.year, o.month, o.day); }