-
Notifications
You must be signed in to change notification settings - Fork 2
/
worker.cpp
56 lines (45 loc) · 1.26 KB
/
worker.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
#include "worker.h"
Worker::Worker(std::string name) : name(name) {
}
std::string Worker::getName() const {
return name;
}
std::vector<Appointment> Worker::getSchedule() const {
return schedule;
}
boost::posix_time::time_duration Worker::getShiftStart() const {
return SHIFT_START;
}
boost::posix_time::time_duration Worker::getAvailableTime() const {
if (schedule.empty()) {
return SHIFT_START;
}
return schedule.back().getTimeOfDayEnd() + BREAK;
}
void Worker::addAppointment(Appointment appointment) {
schedule.push_back(appointment);
}
int Worker::getWorkingMinutes() const {
int mins = 0;
for (auto& appointment : schedule) {
mins += appointment.getLength().minutes();
}
return mins;
}
std::ostream& operator<<(std::ostream& os, const Worker& worker) {
os << worker.name << std::endl;
for (auto& appointment : worker.schedule) {
os << appointment;
}
return os;
}
bool Worker::operator<(const Worker& rhs) {
if (this->getWorkingMinutes() < rhs.getWorkingMinutes()) {
return true;
} else if (this->getWorkingMinutes() == rhs.getWorkingMinutes()) {
if (this->getAvailableTime() < rhs.getAvailableTime()) {
return true;
}
}
return false;
}