mirror of
https://github.com/HowardHinnant/date.git
synced 2025-08-05 05:34:27 +02:00
Fix parse of sys_time with supplied offset, but no offset parse
* If parsing sys_time, and an offset is supplied to be parsed into, but is not parsed into, neither read that parsed offset, nor write to it. The parsed local time offset is assumed to be 0min if no offset is parsed.
This commit is contained in:
@@ -8036,15 +8036,25 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
|
|||||||
{
|
{
|
||||||
using CT = typename std::common_type<Duration, std::chrono::seconds>::type;
|
using CT = typename std::common_type<Duration, std::chrono::seconds>::type;
|
||||||
using detail::round_i;
|
using detail::round_i;
|
||||||
std::chrono::minutes offset_local{};
|
std::chrono::minutes offset_local = std::chrono::minutes::min();
|
||||||
auto offptr = offset ? offset : &offset_local;
|
|
||||||
fields<CT> fds{};
|
fields<CT> fds{};
|
||||||
fds.has_tod = true;
|
fds.has_tod = true;
|
||||||
date::from_stream(is, fmt, fds, abbrev, offptr);
|
date::from_stream(is, fmt, fds, abbrev, &offset_local);
|
||||||
if (!fds.ymd.ok() || !fds.tod.in_conventional_range())
|
if (!fds.ymd.ok() || !fds.tod.in_conventional_range())
|
||||||
is.setstate(std::ios::failbit);
|
is.setstate(std::ios::failbit);
|
||||||
if (!is.fail())
|
if (!is.fail())
|
||||||
tp = round_i<Duration>(sys_days(fds.ymd) - *offptr + fds.tod.to_duration());
|
{
|
||||||
|
if (offset_local != std::chrono::minutes::min())
|
||||||
|
{
|
||||||
|
tp = round_i<Duration>(sys_days(fds.ymd) - offset_local + fds.tod.to_duration());
|
||||||
|
if (offset != nullptr)
|
||||||
|
*offset = offset_local;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tp = round_i<Duration>(sys_days(fds.ymd) + fds.tod.to_duration());
|
||||||
|
}
|
||||||
|
}
|
||||||
return is;
|
return is;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user