Merge pull request #55 from wbenny/master

fix /W4 warnings on MSVC
This commit is contained in:
Toru Niina
2019-04-17 13:16:19 +09:00
committed by GitHub

View File

@@ -25,16 +25,18 @@ inline std::tm localtime_s(const std::time_t* src)
{ {
std::tm dst; std::tm dst;
const auto result = ::localtime_r(src, &dst); const auto result = ::localtime_r(src, &dst);
if(!result) if (!result) { throw std::runtime_error("localtime_r failed."); }
{ return dst;
throw std::runtime_error("localtime_r failed.");
} }
#elif _MSC_VER
inline std::tm localtime_s(const std::time_t* src)
{
std::tm dst;
const auto result = ::localtime_s(&dst, src);
if (result) { throw std::runtime_error("localtime_s failed."); }
return dst; return dst;
} }
#else #else
// XXX: On Windows, std::localtime is thread-safe because they uses thread-local
// storage to store the instance of std::tm. On the other platforms, it may not
// be thread-safe.
inline std::tm localtime_s(const std::time_t* src) inline std::tm localtime_s(const std::time_t* src)
{ {
const auto result = std::localtime(src); const auto result = std::localtime(src);
@@ -360,12 +362,12 @@ struct local_datetime
// can be used to get millisecond & microsecond information. // can be used to get millisecond & microsecond information.
const auto t_diff = tp - const auto t_diff = tp -
std::chrono::system_clock::from_time_t(std::mktime(&time)); std::chrono::system_clock::from_time_t(std::mktime(&time));
this->time.millisecond = std::chrono::duration_cast< this->time.millisecond = static_cast<std::uint16_t>(
std::chrono::milliseconds>(t_diff).count(); std::chrono::duration_cast<std::chrono::milliseconds>(t_diff).count());
this->time.microsecond = std::chrono::duration_cast< this->time.microsecond = static_cast<std::uint16_t>(
std::chrono::microseconds>(t_diff).count(); std::chrono::duration_cast<std::chrono::microseconds>(t_diff).count());
this->time.nanosecond = std::chrono::duration_cast< this->time.nanosecond = static_cast<std::uint16_t>(
std::chrono::nanoseconds >(t_diff).count(); std::chrono::duration_cast<std::chrono::nanoseconds >(t_diff).count());
} }
explicit local_datetime(const std::time_t t) explicit local_datetime(const std::time_t t)