From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from second.openwall.net (second.openwall.net [193.110.157.125]) by inbox.vuxu.org (Postfix) with SMTP id 6FBF0229E9 for ; Sat, 23 Mar 2024 21:41:19 +0100 (CET) Received: (qmail 7557 invoked by uid 550); 23 Mar 2024 20:36:38 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 7523 invoked from network); 23 Mar 2024 20:36:38 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail3; t=1711226466; x=1711485666; bh=iVBHV+98SJHlEwWSsjcABbx8PjPG9wYxhofYQPzzbEY=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=eZFPI45hoLKXEztp/9Jw3XAw/Qew+TBC+REGUoLlJeongptnft9CkkVGAjtOHsakt CxRAgYDPHAZX9bEd1QIos6FIx8JZ7Jx32bCxfGlV0s8KLVXqLSivqUJSoY7T0D7F4W HGzq45caVgqbHobUATpvDOuFEfBW+r1iujj4fOpRVP50uYsMfFQF9YdRIBQflPLqI0 scuKxOCwbxBAuYGla+3Ido3oomLkrO+iPqO3qynTiknQeXWtT0ugIokyMGza0w+5zr UEZwvj9uX3sJbyw6pk/lzoc3H5rkYeCbKzc11hKahHuW1p3YNtOEVhcIOphUDmO2Mb ni/eLORM4/adQ== Date: Sat, 23 Mar 2024 20:40:50 +0000 To: musl@lists.openwall.com From: Alexander Weps Cc: Markus Wichmann Message-ID: <6rPmS4jev9oFFibDdpKZ0mVRWLV3rhRcfqaUKu-5lPP7lc8zz8UH_kgPFA4r8wh1-qrYKfzVBpB0Ss6z4VMANASybmKZMeB9i3W3auYfhMI=@pm.me> In-Reply-To: <20240323201804.GT4163@brightrain.aerifal.cx> References: <20240323123148.GR4163@brightrain.aerifal.cx> <5zS95V9QjlCRMv6JvbMFzFIOvxQTigAsEvu0YNSYzcu1ZHdki6sue6yqDXeWlRcSe_jhCQxHdHc0fvKu-3H7lCvyAeYgQTsK7KWMepbly3Y=@pm.me> <20240323153146.GS4163@brightrain.aerifal.cx> <-44SZR0LbVoyD5lp_9VrAFnIjGNbDvibCVUYEprqMToPidjopTHM4aLZuhjomrGJtvpGrc_gjrgK6roKWwunjEkk1y-BKRhtlGpWjnslQNA=@pm.me> <20240323201804.GT4163@brightrain.aerifal.cx> Feedback-ID: 20507743:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [musl] Broken mktime calculations when crossing DST boundary Yes, the behavior is the same here glibc and musl and it can't reliably det= ermine start of the day etc. Which is I assume expected. That's why there is tm_isdst =3D -1. I don't see any reliable way to determine beginning of the day without it. If I want to get beginning of the day I do it this way: before: 2010-10-31 14:00:00 CET tm_sec: 0 tm_min: 0 tm_hour: 14 tm_mday: 31 tm_mon: 9 tm_year: 110 tm_wday: 0 tm_yday: 303 tm_isdst: 0 tm_gmtoff: 3600 tm_zone: CET tm.tm_isdst =3D -1; <-- setting tm_isdst =3D -1 tm.tm_hour =3D 0; mktime(&tm); after: 2010-10-31 00:00:00 CEST tm_sec: 0 tm_min: 0 tm_hour: 0 tm_mday: 31 tm_mon: 9 tm_year: 110 tm_wday: 0 tm_yday: 303 tm_isdst: 1 tm_gmtoff: 7200 tm_zone: CEST Is there a way, how to reliable get beginning of day etc. without tm_isdst = =3D -1. AW On Saturday, March 23rd, 2024 at 21:18, Rich Felker wrote= : > On Sat, Mar 23, 2024 at 06:57:21PM +0000, Alexander Weps wrote: > > > So, in the meantime, I was debugging with not setting tm_isdst =3D -1; > > > > This causes pretty annoying behavior: > > > > before: 2010-10-31 14:00:00 > > > > tm_sec: 0 > > tm_min: 0 > > tm_hour: 14 > > tm_mday: 31 > > tm_mon: 9 > > tm_year: 110 > > tm_wday: 0 > > tm_yday: 0 > > tm_isdst: 0 > > tm_gmtoff: 3600 > > tm_zone: CET > > > > tm->tm_hour =3D 0; <-- reset hour field > > mktime(&tm); > > > > after: 2010-10-31 01:00:00 CEST <-- 10:00:00 instead of 00:00:00 > > > I guess you meant 01:00:00 not 10:00:00. This is expected. You asked > mktime to normalize a time expressed in standard (non-DST, CET) time > but referring to a time at which DST is in effect. After > normalization, it expresses that time in DST (CEST). Since there is no > tm_isdst<0 (the only source of arbitrary implementation choices) > involved, you will find glibc and all other implementations do exactly > the same thing here. > > > tm_sec: 0 > > tm_min: 0 > > tm_hour: 1 > > tm_mday: 31 > > tm_mon: 9 > > tm_year: 110 > > tm_wday: 0 > > tm_yday: 303 > > tm_isdst: 1 > > tm_gmtoff: 7200 > > tm_zone: CEST > > > > tm->tm_hour =3D 0; > > mktime(&tm); > > > > after: 2010-10-31 00:00:00 CEST <-- second run gives a correct value > > tm_sec: 0 > > tm_min: 0 > > tm_hour: 0 > > tm_mday: 31 > > tm_mon: 9 > > tm_year: 110 > > tm_wday: 0 > > tm_yday: 303 > > tm_isdst: 1 > > tm_gmtoff: 7200 > > tm_zone: CEST > > > > This basically means that setting field twice produces different > > value each time: > > > No it does not. After the first time, tm_isdst is 1. Now when you > change the hour to 0, you are giving it a time expressed in DST. Since > DST is in effect at this time, it's already normalized, and you get > back what you put in. > > Rich