Switch to floor in format

Need to round towards negative infinity for dates prior to the epoch,
else the wrong answer gets formatted.
This commit is contained in:
Howard Hinnant
2016-08-27 13:22:27 -04:00
parent 343e8299c7
commit fcdca67c5b

3
date.h
View File

@@ -4015,7 +4015,8 @@ format(const std::locale& loc, std::basic_string<CharT, Traits> fmt,
}
auto& f = use_facet<time_put<CharT>>(loc);
basic_ostringstream<CharT, Traits> os;
auto tt = system_clock::to_time_t(time_point_cast<system_clock::duration>(sys_time<Duration>{tp.time_since_epoch()}));
auto tt = system_clock::to_time_t(
floor<system_clock::duration>(sys_time<Duration>{tp.time_since_epoch()}));
std::tm tm{};
#ifndef _MSC_VER
gmtime_r(&tt, &tm);