-
Notifications
You must be signed in to change notification settings - Fork 0
/
shift.cpp
40 lines (31 loc) · 908 Bytes
/
shift.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
#include "shift.h"
void Shift::clockIn(std::string time){
if (actualStart == "")
actualStart = time;
}
void Shift::clockOut(std::string time){
if (actualEnd == "")
actualEnd = time;
}
std::string Shift::beginTime(){
return actualStart;
}
std::string Shift::endTime(){
return actualEnd;
}
int Shift::timeWorked(){
// presuming start and end times are in 24hr
// and Hour:Minute:Second
if ( beginTime() == "" || endTime() == "")
return 0;
float time = 0.0; //fractional hours
time = std::stoi(endTime().substr(0,2)) -
std::stoi(beginTime().substr(0,2));
//minutes to hours
time += (std::stoi(endTime().substr(3,2)) -
std::stoi(beginTime().substr(3,2))) / 60.0;
//seconds to hours
time += (std::stoi(endTime().substr(6,2)) -
std::stoi(beginTime().substr(6,2))) / 3600.0;
return time;
}