Protect from overflow when minutes is 32 bits

This commit is contained in:
Howard Hinnant 2016-05-31 11:12:20 -04:00
parent 630d67ce0d
commit a89aab05cf
2 changed files with 5 additions and 4 deletions

4
date.h
View File

@ -3633,7 +3633,7 @@ public:
CONSTCD14 explicit operator precision() const NOEXCEPT
{
return to24hr() + m_ + s_;
return to24hr() + s_ + m_;
}
CONSTCD14 precision to_duration() const NOEXCEPT
@ -3714,7 +3714,7 @@ public:
CONSTCD14 explicit operator precision() const NOEXCEPT
{
return to24hr() + m_ + s_ + sub_s_;
return to24hr() + s_ + sub_s_ + m_;
}
CONSTCD14 precision to_duration() const NOEXCEPT

5
tz.cpp
View File

@ -708,7 +708,8 @@ MonthDayTime::to_sys_days(date::year y) const
sys_seconds
MonthDayTime::to_time_point(date::year y) const
{
return to_sys_days(y) + h_ + m_ + s_;
// Add seconds first to promote to largest rep early to prevent overflow
return to_sys_days(y) + s_ + h_ + m_;
}
void
@ -871,7 +872,7 @@ operator<<(std::ostream& os, const MonthDayTime& x)
}
break;
}
os << date::make_time(x.h_ + x.m_ + x.s_);
os << date::make_time(x.s_ + x.h_ + x.m_);
if (x.zone_ == tz::utc)
os << "UTC ";
else if (x.zone_ == tz::standard)