From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 13AA53875427; Tue, 9 Apr 2024 23:29:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 13AA53875427 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1712705383; bh=KS8piphu4aIJn1BajKiYBxZtm+9/WLYynxGNVOI4EXs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=KNFBwHAStP2rbOhVzs0UkatdJyhDizofJmIJ9qFfQJSuNCVI/M+pK1uZ4x0Po29tT i/ppNMpvVrMxdHIsh7nZyP7x/UUHpiU2gc39/bxZ2By4Iooc2fWR7B8j2JmC8t+OxX aHk3VpT2lMl5xZxGxR0MPjIKrO3MbQeC9NTJJMwY= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/114645] std::chrono::current_zone ignores $TZ on Linux Date: Tue, 09 Apr 2024 23:29:42 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 13.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: WONTFIX X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114645 --- Comment #15 from Jonathan Wakely --- (In reply to Hristo Venev from comment #13) > > $TZ allows you to override it per-process (and even change it during th= e lifetime of a process by using setenv and tzset). We don't support that f= or current_zone(). >=20 > /etc/localtime can also change. But not in a racy way. The filesystem serializes those changes so that inspecting the symlink with readlink(3) gives a single race-free answer at = any one time. And if the application wants to query current_zone() once and then reuse the result of that query, it can, because the time_zone* is a value h= eld by the application itself. That's an advantage of the std::chrono design wh= ich is absent from libc, where the application has very little control over the hidden state that libc maintains for time zone info. > > The intent is to infer an IANA time zone from the /etc/localtime symlin= k, if possible. If the intent was to match libc, it would look at $TZ. I've= discussed this exact question with the author of that library (which is th= e origin of the std::chrono components too). What I said in comment 8 above= is paraphrasing what he said. >=20 > Point taken. Still, do you have any explanation for why this behavior was > chosen? Because the environment cannot be accessed safely, and because $TZ was traditionally used for POSIX time zones, which are inferior to the IANA zon= es in nearly every way (see the "POSIX style time zones" section of https://stackoverflow.com/tags/timezone/info for more details). > > Just do the easy thing yourself. >=20 > The easy thing being to fix all applications that currently use or will e= ver > use current_zone(). Fun times ahead... Well they should not be assuming current_zone() uses $TZ in the first place= - that has never been claimed or documented by any reputable source. You only need to "fix" the ones that were relying on something that was never part of the API.=