-
Notifications
You must be signed in to change notification settings - Fork 0
/
Timestamp.cpp
67 lines (60 loc) · 1.38 KB
/
Timestamp.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
#include "Timestamp.h"
#include <windows.h>
Timestamp::Timestamp(const int _y = 0, const int _mo = 0, const int _d = 0, const int _h=0, const int _mi = 0, const int _s = 0)
{
year = _y;
month = _mo;
day = _d;
hour = _h;
minute = _mi;
second = _s;
}
void Timestamp::set()
{
SYSTEMTIME now;
GetLocalTime(&now);
year = now.wYear;
month = now.wMonth;
day = now.wDay;
hour = now.wHour;
minute = now.wMinute;
second = now.wSecond;
}
bool Timestamp::operator==(const Timestamp& t) const
{
return year == t.year && month == t.month && day == t.day && hour == t.hour && minute == t.minute && second == t.second;
}
bool Timestamp::operator<(const Timestamp& t) const
{
{
if (year == t.year)
{
if (month == t.month)
{
if (day == t.day)
{
if (hour == t.hour)
return minute == t.minute ? second < t.second : minute < t.minute;
return hour < t.hour;
}
return day < t.day;
}
return month < t.month;
}
return year < t.year;
}
}
bool Timestamp::operator<=(const Timestamp& t) const
{
return (*this)<t||(*this)==t;
}
std::istream& operator>>(std::istream& in, Timestamp& A)
{
in >> A.year >> A.month >> A.day >> A.hour >> A.minute >> A.second;
return in;
}
std::ostream& operator<<(std::ostream& out, Timestamp& A)
{
out << A.year << ' ' << A.month << ' ' << A.day << ' ' << A.hour << ' ' << A.minute << ' ' << A.second << std::endl;
return out;
}