public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/114279] New: utc_clock does not support leap seconds
@ 2024-03-08 6:51 gnaggnoyil at gmail dot com
2024-03-08 7:59 ` [Bug libstdc++/114279] " redi at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: gnaggnoyil at gmail dot com @ 2024-03-08 6:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114279
Bug ID: 114279
Summary: utc_clock does not support leap seconds
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: gnaggnoyil at gmail dot com
Target Milestone: ---
When using current GCC trunk, the program
#include <chrono>
#include <sstream>
#include <iostream>
int main(){
std::stringstream stream;
stream << "20161231-23:59:60.035";
std::chrono::utc_time<std::chrono::milliseconds> utc_tp;
(void)std::chrono::from_stream(stream, "%4Y%2m%2d-%2H:%2M:%S", utc_tp);
std::cout << utc_tp << std::endl;
return 0;
}
gives the following output:
2017-01-01 00:00:00.035
which does not seems to give leap seconds into consideration.
The current standard working draft [time.clock.utc.overview]#1 states
In contrast to sys_time, which does not take leap seconds into account,
utc_clock and its associated time_point, utc_time, count time, including leap
seconds, since 1970-01-01 00:00:00 UTC.
So I think the current libstdc++ implementation here is not conforming the
standard.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libstdc++/114279] utc_clock does not support leap seconds
2024-03-08 6:51 [Bug libstdc++/114279] New: utc_clock does not support leap seconds gnaggnoyil at gmail dot com
@ 2024-03-08 7:59 ` redi at gcc dot gnu.org
2024-03-08 11:21 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2024-03-08 7:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114279
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It certainly does take leap seconds into account, as demonstrated by the output
example below the text you quoted, which is reproduced in the testsuite:
https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libstdc%2B%2B-v3/testsuite/std/time/clock/utc/io.cc;h=55c53dc4057fe90b8a0f7192cc38ffe313f5afd4;hb=HEAD
And also:
https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libstdc%2B%2B-v3/testsuite/std/time/clock/utc/leap_second_info.cc;h=2fabda494234a48dc2920e291f5a92a8fe1d02fa;hb=HEAD
This seems to be just a bug in the from_stream overload, not utc_clock.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libstdc++/114279] utc_clock does not support leap seconds
2024-03-08 6:51 [Bug libstdc++/114279] New: utc_clock does not support leap seconds gnaggnoyil at gmail dot com
2024-03-08 7:59 ` [Bug libstdc++/114279] " redi at gcc dot gnu.org
@ 2024-03-08 11:21 ` redi at gcc dot gnu.org
2024-03-09 0:29 ` cvs-commit at gcc dot gnu.org
2024-03-09 0:31 ` redi at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2024-03-08 11:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114279
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |13.3
Assignee|unassigned at gcc dot gnu.org |redi at gcc dot gnu.org
Ever confirmed|0 |1
Last reconfirmed| |2024-03-08
Status|UNCONFIRMED |ASSIGNED
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fix:
--- a/libstdc++-v3/include/bits/chrono_io.h
+++ b/libstdc++-v3/include/bits/chrono_io.h
@@ -2854,9 +2854,19 @@ namespace __detail
basic_string<_CharT, _Traits, _Alloc>* __abbrev = nullptr,
minutes* __offset = nullptr)
{
- sys_time<_Duration> __st;
- if (chrono::from_stream(__is, __fmt, __st, __abbrev, __offset))
- __tp = chrono::time_point_cast<_Duration>(utc_clock::from_sys(__st));
+ minutes __off{};
+ if (!__offset)
+ __offset = &__off;
+ using __format::_ChronoParts;
+ auto __need = _ChronoParts::_Year | _ChronoParts::_Month
+ | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
+ __detail::_Parser_t<_Duration> __p(__need);
+ if (__p(__is, __fmt, __abbrev, __offset))
+ {
+ auto __ut = utc_clock::from_sys(__p._M_sys_days) + __p._M_time
+ - *__offset;
+ __tp = chrono::time_point_cast<_Duration>(__ut);
+ }
return __is;
}
But we also need a change to the other from_stream overloads that are defined
in terms of utc_time, so that they don't allow 60s.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libstdc++/114279] utc_clock does not support leap seconds
2024-03-08 6:51 [Bug libstdc++/114279] New: utc_clock does not support leap seconds gnaggnoyil at gmail dot com
2024-03-08 7:59 ` [Bug libstdc++/114279] " redi at gcc dot gnu.org
2024-03-08 11:21 ` redi at gcc dot gnu.org
@ 2024-03-09 0:29 ` cvs-commit at gcc dot gnu.org
2024-03-09 0:31 ` redi at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-09 0:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114279
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:
https://gcc.gnu.org/g:f4a52c184d608325c14338b57f464f7d0bbc7526
commit r14-9405-gf4a52c184d608325c14338b57f464f7d0bbc7526
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Fri Mar 8 14:41:47 2024 +0000
libstdc++: Fix parsing of leap seconds as chrono::utc_time [PR114279]
Implementing all chrono::from_stream overloads in terms of
chrono::sys_time meant that a leap second time like 23:59:60.001 cannot
be parsed, because that cannot be represented in a sys_time.
The fix to support parsing leap seconds as utc_time is to convert the
parsed date to utc_time<days> and then add the parsed time to that,
which allows the result to land in a leap second, rather than doing all
the arithmetic with sys_time which doesn't have leap seconds.
For local_time we also allow %S to parse a 60s value, because doing
otherwise might disallow some valid uses. We can't know all use cases
users have for treating times as local_time.
For all other clocks, we can reject times that have 60 or 60.nnn as the
seconds part, because that cannot occur in a valid UNIX, GPS, or TAI
time. Since our chrono::file_clock uses sys_time, it can't occur for
that clock either.
In order to support this a new _M_is_leap_second member is needed in the
_Parser type. This can be added at the end, where most targets currently
have padding bytes. Similar to what I did recently for formatter _Spec
structs, we can also reserve additional padding bits for future
expansion.
This also fixes bugs in the from_stream overloads for utc_time,
tai_time, gps_time, and file_time, which were not using time_point_cast
to explicitly convert to the result type. That's needed because the
result type might have lower precision than the value returned from
from_sys or from_utc, which has a precision no lower than seconds.
libstdc++-v3/ChangeLog:
PR libstdc++/114279
* include/bits/chrono_io.h (_Parser::_M_is_leap_second): New
data member.
(_Parser::_M_reserved): Reserve padding bits for future use.
(_Parser::operator()): Set _M_is_leap_second if %S reads 60s.
(from_stream): Only allow _M_is_leap_second for utc_time and
local_time. Adjust arithmetic for utc_time so that leap seconds
are preserved. Use time_point_cast to convert to a possibly
lower-precision result type.
* testsuite/std/time/parse.cc: Move to ...
* testsuite/std/time/parse/parse.cc: ... here.
* testsuite/std/time/parse/114279.cc: New test.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libstdc++/114279] utc_clock does not support leap seconds
2024-03-08 6:51 [Bug libstdc++/114279] New: utc_clock does not support leap seconds gnaggnoyil at gmail dot com
` (2 preceding siblings ...)
2024-03-09 0:29 ` cvs-commit at gcc dot gnu.org
@ 2024-03-09 0:31 ` redi at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2024-03-09 0:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114279
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Target Milestone|13.3 |14.0
Status|ASSIGNED |RESOLVED
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed for GCC 14. Thanks for the report.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-03-09 0:31 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-08 6:51 [Bug libstdc++/114279] New: utc_clock does not support leap seconds gnaggnoyil at gmail dot com
2024-03-08 7:59 ` [Bug libstdc++/114279] " redi at gcc dot gnu.org
2024-03-08 11:21 ` redi at gcc dot gnu.org
2024-03-09 0:29 ` cvs-commit at gcc dot gnu.org
2024-03-09 0:31 ` redi at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).