-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDayTime.cpp
executable file
·52 lines (44 loc) · 1.2 KB
/
DayTime.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
#include "DayTime.h"
DayTime::DayTime(int hours,int minutes)
{
this->minutes=minutes%60;
this->hours=(hours+minutes/60)%24;
}
DayTime::DayTime()
{
time_t currTime;
time(&currTime); // Get current time
struct tm* currTimeStruct = localtime(&currTime); // Get time as structure
this->hours=currTimeStruct->tm_hour;
this->minutes=currTimeStruct->tm_min;
}
void DayTime::show() const
{
// Show time in format HH:MM
cout << (this->hours<10 ? "0":"") << this->hours << ":" << (this->minutes<10 ? "0":"") <<this->minutes;
}
int DayTime::getHours() const
{
return this->hours;
}
int DayTime::getMinutes() const
{
return this->minutes;
}
int DayTime::compareDayTime(const DayTime dtime) const
{
// This function return -1 if the operating object is "bigger" (after) dtime parameter,
// returns 1 if dtime is after the operating object, 0 if they are equal.
if (this->hours > dtime.getHours())
return -1;
else if (this->hours < dtime.getHours())
return 1;
else{
if (this->minutes > dtime.getMinutes())
return -1;
else if (this->minutes < dtime.getMinutes())
return 1;
else
return 0;
}
}