-
Notifications
You must be signed in to change notification settings - Fork 0
/
date.cpp
executable file
·71 lines (62 loc) · 1.61 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
#include <vector>
#include <map>
#include <iostream>
#include <ostream>
#include <fstream>
#include <string>
#include <set>
#include "date.h"
bool Date::operator<=(const Date& obj) {
return ((*this < obj) || *this == obj);
}
bool Date::operator==(const Date& obj) const{
return (year == obj.year && day == obj.day && month == obj.month && hours == obj.hours && mins == obj.mins);
}
bool Date::operator!=(const Date& obj) const {
return !(*this == obj);
}
bool Date::operator<(const Date& rhs) const{
if (year < rhs.year) {
return true;
} else if (year == rhs.year) {
if (month < rhs.month) {
return true;
} else if (month == rhs.month) {
if (day < rhs.day) {
return true;
} else if (day == rhs.day) {
if (hours < rhs.hours) {
return true;
} else if (hours == rhs.hours) {
return mins < rhs.mins;
}
}
}
}
return false;
}
std::string Date::getDate() const{
std::string m = std::to_string(month);
std::string d = std::to_string(day);
std::string y = std::to_string(year);
if (month < 10)
m = '0' + m;
if (day < 10)
d = '0' + d;
if (year < 10)
y = '0' + y;
if (year < 100)
y = '0' + y;
if (year < 1000)
y = '0' + y;
return m + '/' + d + '/' + y;
}
std::string Date::getTime() const{
std::string h = std::to_string(hours);
std::string m = std::to_string(mins);
if (hours < 10)
h = '0' + h;
if (mins < 10)
m = '0' + m;
return h + ':' + m;
}