clock: iteration 1
This commit is contained in:
parent
e9c27cd864
commit
e88ba7bd2e
1 changed files with 7 additions and 7 deletions
|
|
@ -10,12 +10,12 @@ const minutes_t minutes_per_hour = 60;
|
|||
const hours_t hours_per_day = 24;
|
||||
const total_t minutes_per_day = hours_per_day * minutes_per_hour;
|
||||
|
||||
inline void make_date_independent(total_t total_minutes)
|
||||
inline void wrap_midnight(total_t &total_minutes)
|
||||
{
|
||||
while (total_minutes < 0)
|
||||
total_minutes += minutes_per_day;
|
||||
total_minutes %= minutes_per_day;
|
||||
|
||||
total_minutes = total_minutes % minutes_per_day;
|
||||
if (total_minutes < 0)
|
||||
total_minutes += minutes_per_day;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -24,7 +24,7 @@ inline void make_date_independent(total_t total_minutes)
|
|||
clock::clock(hours_t hours, minutes_t minutes)
|
||||
{
|
||||
total_minutes_ = minutes_per_hour*hours + minutes;
|
||||
make_date_independent(total_minutes_);
|
||||
wrap_midnight(total_minutes_);
|
||||
}
|
||||
|
||||
bool clock::operator==(const clock &other) const
|
||||
|
|
@ -47,7 +47,7 @@ clock clock::plus(minutes_t minutes) const
|
|||
clock result(*this);
|
||||
|
||||
result.total_minutes_ += minutes;
|
||||
make_date_independent(result.total_minutes_);
|
||||
wrap_midnight(result.total_minutes_);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -59,7 +59,7 @@ clock clock::minus(minutes_t minutes) const
|
|||
|
||||
clock::operator std::string() const
|
||||
{
|
||||
minutes_t minutes = total_minutes_ % minutes_per_hour
|
||||
minutes_t minutes = total_minutes_ % minutes_per_hour;
|
||||
hours_t hours = total_minutes_ / minutes_per_hour;
|
||||
|
||||
char buff[6];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue