45 lines
1.2 KiB
C++
45 lines
1.2 KiB
C++
|
#include"headers/Park_time.h"
|
||
|
#include <iostream>
|
||
|
#include <ctime>
|
||
|
|
||
|
|
||
|
Park_time::Park_time(int c_id, int s_id)
|
||
|
: customer_id { c_id }
|
||
|
, spot_id { s_id }
|
||
|
, duration { 0 }
|
||
|
, start { high_resolution_clock::now() }
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void Park_time::clock_out(int c_id, int s_id)
|
||
|
{
|
||
|
|
||
|
if (c_id != customer_id) {
|
||
|
std::cout << "wrong customer id, you are at the wrong location";
|
||
|
return;
|
||
|
}
|
||
|
if (s_id != spot_id) {
|
||
|
std::cout << "Wrong spot id, you're at the wrong location";
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (!duration) {
|
||
|
end = high_resolution_clock::now();
|
||
|
duration = duration_cast<seconds>(end - start).count(); // use mins later
|
||
|
|
||
|
} else {
|
||
|
std::cout << "Already clocked out. Something is wrong \n";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
std::ostream& operator<<(std::ostream& os, const Park_time & pt){
|
||
|
std::time_t start_ = system_clock::to_time_t(pt.start);
|
||
|
std::time_t end_ = system_clock::to_time_t(pt.end);
|
||
|
os << "- - - - - - - - - - - - - - - - - - - -\n";
|
||
|
os << "Clocked in :" << std::ctime(&start_);
|
||
|
os << "clocked out : " << std::ctime(&end_);
|
||
|
os << "duration : " << pt.duration << "\n";
|
||
|
os << "- - - - - - - - - - - - - - - - - - - -\n";
|
||
|
return os;
|
||
|
}
|