From e32a0d809c3d3c4797826825dc2d0b287281e3b2 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Fri, 4 Jul 2025 23:52:00 -0400 Subject: [PATCH] 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. --- include/date/date.h | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/include/date/date.h b/include/date/date.h index 73274fd..53c4d1c 100644 --- a/include/date/date.h +++ b/include/date/date.h @@ -8036,15 +8036,25 @@ from_stream(std::basic_istream& is, const CharT* fmt, { using CT = typename std::common_type::type; using detail::round_i; - std::chrono::minutes offset_local{}; - auto offptr = offset ? offset : &offset_local; + std::chrono::minutes offset_local = std::chrono::minutes::min(); fields fds{}; 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()) is.setstate(std::ios::failbit); if (!is.fail()) - tp = round_i(sys_days(fds.ymd) - *offptr + fds.tod.to_duration()); + { + if (offset_local != std::chrono::minutes::min()) + { + tp = round_i(sys_days(fds.ymd) - offset_local + fds.tod.to_duration()); + if (offset != nullptr) + *offset = offset_local; + } + else + { + tp = round_i(sys_days(fds.ymd) + fds.tod.to_duration()); + } + } return is; }