2022-11-02 22:41:16 +03:00
|
|
|
#include "time.h"
|
|
|
|
#include <string>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using std::cout, std::endl, std::vector, std::string_view, std::string;
|
|
|
|
|
|
|
|
Time::Time(int hours, int minutes, int seconds)
|
|
|
|
{
|
|
|
|
mHours = hours;
|
|
|
|
mMinutes = minutes;
|
|
|
|
mSeconds = seconds;
|
|
|
|
}
|
|
|
|
|
|
|
|
Time::Time(string_view s)
|
|
|
|
{
|
|
|
|
string buf;
|
2022-11-02 23:17:06 +03:00
|
|
|
buf = s.substr(0, 2);
|
2022-11-02 22:41:16 +03:00
|
|
|
mHours = stoi(buf);
|
2022-11-02 23:17:06 +03:00
|
|
|
buf = s.substr(3, 2);
|
2022-11-02 22:41:16 +03:00
|
|
|
mMinutes = stoi(buf);
|
2022-11-02 23:17:06 +03:00
|
|
|
buf = s.substr(6, 2);
|
2022-11-02 22:41:16 +03:00
|
|
|
mSeconds = stoi(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
Time::Time():Time(0, 0, 0)
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
Time Time::operator+(Time b) const
|
|
|
|
{
|
|
|
|
return Time((mHours + b.mHours + (mMinutes + b.mMinutes) / 60) % 24,
|
|
|
|
(mMinutes + b.mMinutes +
|
|
|
|
(mSeconds + b.mSeconds) / 60) % 60,
|
|
|
|
(mSeconds + b.mSeconds) % 60);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Time::hours() const
|
|
|
|
{
|
|
|
|
return mHours;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Time::minutes() const
|
|
|
|
{
|
|
|
|
return mMinutes;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Time::seconds() const
|
|
|
|
{
|
|
|
|
return mSeconds;
|
|
|
|
}
|
|
|
|
|
|
|
|
vector < Time > getTimesFromString(string_view s)
|
|
|
|
{
|
|
|
|
vector < Time > res;
|
|
|
|
for (int i = 0, size = s.size(); i < size; i += 9) {
|
|
|
|
res.push_back(Time(s.substr(i, 9)));
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2022-11-02 23:17:06 +03:00
|
|
|
Time sumTimes(const vector < Time > &v)
|
2022-11-02 22:41:16 +03:00
|
|
|
{
|
|
|
|
Time res;
|
|
|
|
for (int i = 0, size = v.size(); i < size; ++i) {
|
|
|
|
res = res + v[i];
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream & operator<<(std::ostream & out, Time t)
|
|
|
|
{
|
|
|
|
out << std::setw(2) << std::setfill('0') << t.mHours
|
|
|
|
<< ":"
|
|
|
|
<< std::setw(2) << std::setfill('0') << t.mMinutes
|
|
|
|
<< ":" << std::setw(2) << std::setfill('0') << t.mSeconds;
|
|
|
|
return out;
|
|
|
|
}
|