Fix formatting bug for utc_time.

This commit is contained in:
Howard Hinnant
2017-03-30 14:44:42 -04:00
parent 3495c513a1
commit d29cd4e343

38
date.h
View File

@@ -4257,11 +4257,10 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
{ {
tm = std::tm{}; tm = std::tm{};
auto const& ymd = fds.ymd; auto const& ymd = fds.ymd;
time_of_day<seconds> hms{floor<seconds>(fds.tod.to_duration())};
auto ld = local_days(ymd); auto ld = local_days(ymd);
tm.tm_sec = static_cast<int>(hms.seconds().count()); tm.tm_sec = static_cast<int>(fds.tod.seconds().count());
tm.tm_min = static_cast<int>(hms.minutes().count()); tm.tm_min = static_cast<int>(fds.tod.minutes().count());
tm.tm_hour = static_cast<int>(hms.hours().count()); tm.tm_hour = static_cast<int>(fds.tod.hours().count());
tm.tm_mday = static_cast<int>(static_cast<unsigned>(ymd.day())); tm.tm_mday = static_cast<int>(static_cast<unsigned>(ymd.day()));
tm.tm_mon = static_cast<int>(static_cast<unsigned>(ymd.month()) - 1); tm.tm_mon = static_cast<int>(static_cast<unsigned>(ymd.month()) - 1);
tm.tm_year = static_cast<int>(ymd.year()) - 1900; tm.tm_year = static_cast<int>(ymd.year()) - 1900;
@@ -4515,19 +4514,18 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
case 'M': case 'M':
if (command) if (command)
{ {
time_of_day<minutes> hms{floor<minutes>(fds.tod.to_duration())};
if (modified == CharT{'O'}) if (modified == CharT{'O'})
{ {
const CharT f[] = {'%', modified, *fmt}; const CharT f[] = {'%', modified, *fmt};
tm.tm_min = static_cast<int>(hms.minutes().count()); tm.tm_min = static_cast<int>(fds.tod.minutes().count());
facet.put(os, os, os.fill(), &tm, begin(f), end(f)); facet.put(os, os, os.fill(), &tm, begin(f), end(f));
modified = CharT{}; modified = CharT{};
} }
else if (modified == CharT{}) else if (modified == CharT{})
{ {
if (hms.minutes() < minutes{10}) if (fds.tod.minutes() < minutes{10})
os << CharT{'0'}; os << CharT{'0'};
os << hms.minutes().count(); os << fds.tod.minutes().count();
} }
else else
{ {
@@ -4578,11 +4576,10 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
{ {
if (modified == CharT{}) if (modified == CharT{})
{ {
time_of_day<seconds> hms{floor<seconds>(fds.tod.to_duration())};
const CharT f[] = {'%', *fmt}; const CharT f[] = {'%', *fmt};
tm.tm_hour = static_cast<int>(hms.hours().count()); tm.tm_hour = static_cast<int>(fds.tod.hours().count());
tm.tm_min = static_cast<int>(hms.minutes().count()); tm.tm_min = static_cast<int>(fds.tod.minutes().count());
tm.tm_sec = static_cast<int>(hms.seconds().count()); tm.tm_sec = static_cast<int>(fds.tod.seconds().count());
facet.put(os, os, os.fill(), &tm, begin(f), end(f)); facet.put(os, os, os.fill(), &tm, begin(f), end(f));
} }
else else
@@ -4600,13 +4597,12 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
{ {
if (modified == CharT{}) if (modified == CharT{})
{ {
time_of_day<minutes> hms{floor<minutes>(fds.tod.to_duration())}; if (fds.tod.hours() < hours{10})
if (hms.hours() < hours{10})
os << CharT{'0'}; os << CharT{'0'};
os << hms.hours().count() << CharT{':'}; os << fds.tod.hours().count() << CharT{':'};
if (hms.minutes() < minutes{10}) if (fds.tod.minutes() < minutes{10})
os << CharT{'0'}; os << CharT{'0'};
os << hms.minutes().count(); os << fds.tod.minutes().count();
} }
else else
{ {
@@ -4844,11 +4840,9 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
else else
{ {
tm = std::tm{}; tm = std::tm{};
using CT = typename common_type<seconds, Duration>::type; tm.tm_sec = static_cast<int>(fds.tod.seconds().count());
time_of_day<CT> hms{duration_cast<CT>(fds.tod.to_duration())}; tm.tm_min = static_cast<int>(fds.tod.minutes().count());
tm.tm_sec = static_cast<int>(hms.seconds().count()); tm.tm_hour = static_cast<int>(fds.tod.hours().count());
tm.tm_min = static_cast<int>(hms.minutes().count());
tm.tm_hour = static_cast<int>(hms.hours().count());
CharT f[3] = {'%'}; CharT f[3] = {'%'};
auto fe = begin(f) + 1; auto fe = begin(f) + 1;
if (modified == CharT{'E'}) if (modified == CharT{'E'})