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=-3.1 required=5.0 tests=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 AE9B322562 for ; Sat, 23 Mar 2024 21:18:01 +0100 (CET) Received: (qmail 32686 invoked by uid 550); 23 Mar 2024 20:13:18 -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 32641 invoked from network); 23 Mar 2024 20:13:17 -0000 Date: Sat, 23 Mar 2024 16:18:04 -0400 From: Rich Felker To: Alexander Weps Cc: musl@lists.openwall.com, Markus Wichmann Message-ID: <20240323201804.GT4163@brightrain.aerifal.cx> References: <528SeRFaPfDw7fA4kqKDlio1U4RB_t9nmUemPcWw9_t1e2hBDpXYFmOqxAC37szgYvAVtmTuXWsmT64SSN3cSQFVdrQqXUAgkdTMPZQ0bg0=@pm.me> <20240323123148.GR4163@brightrain.aerifal.cx> <5zS95V9QjlCRMv6JvbMFzFIOvxQTigAsEvu0YNSYzcu1ZHdki6sue6yqDXeWlRcSe_jhCQxHdHc0fvKu-3H7lCvyAeYgQTsK7KWMepbly3Y=@pm.me> <20240323153146.GS4163@brightrain.aerifal.cx> <-44SZR0LbVoyD5lp_9VrAFnIjGNbDvibCVUYEprqMToPidjopTHM4aLZuhjomrGJtvpGrc_gjrgK6roKWwunjEkk1y-BKRhtlGpWjnslQNA=@pm.me> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] Broken mktime calculations when crossing DST boundary 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 = -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 = 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 = 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