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 7632F214B9 for ; Sat, 23 Mar 2024 20:33:47 +0100 (CET) Received: (qmail 27969 invoked by uid 550); 23 Mar 2024 19:29:06 -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 27934 invoked from network); 23 Mar 2024 19:29:06 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail3; t=1711222414; x=1711481614; bh=tOUQiqMsKeqsFQAf1sho3jqrfiQ8iOLocspa6JIK/Yg=; 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=kq6/+CVMEkqe+Rxg5bi00cFseUkorr/7FhOOMQIH1pTQb7UWD8tYD/31umlccmEJq 9zgSujSrc1aKz4qOVTNCGemzjPBrQninPmsScfun0T9Mpuc6fVG783cSdzC3zZXZC1 rDsuOgQ5jB5yNOnSJ3q54+PILF1wUFtPBDtSxlNfU3oWHAnxK6usKKB9lFncLUZwmY rvZli1Va8MUOZeAnr0PLKPSibiJJvDd9gmFht28oNhjQiiGhT751W3UJcFUr6NId09 7fQgK2yjhDBkCoDAf9Sbs5gStLGTu+o+rhH7/GYyI0dL4IXf2axlqx/Cph/b4GBGEg L8VqZaYvmCo2Q== Date: Sat, 23 Mar 2024 19:33:16 +0000 To: musl@lists.openwall.com From: Alexander Weps Cc: Markus Wichmann Message-ID: In-Reply-To: References: <20240323123148.GR4163@brightrain.aerifal.cx> <5zS95V9QjlCRMv6JvbMFzFIOvxQTigAsEvu0YNSYzcu1ZHdki6sue6yqDXeWlRcSe_jhCQxHdHc0fvKu-3H7lCvyAeYgQTsK7KWMepbly3Y=@pm.me> <20240323153146.GS4163@brightrain.aerifal.cx> <-44SZR0LbVoyD5lp_9VrAFnIjGNbDvibCVUYEprqMToPidjopTHM4aLZuhjomrGJtvpGrc_gjrgK6roKWwunjEkk1y-BKRhtlGpWjnslQNA=@pm.me> 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 What is the reliable way to get start of this day and similar? Seems there is just no way if you say tm_isdst =3D -1 is not a proper way? For cron calculations I have to move between seconds, minutes, hours, days,= months etc. reliably. AW On Saturday, March 23rd, 2024 at 19:57, Alexander Weps wr= ote: > 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 > 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 ea= ch time: > > AW > > > > > On Saturday, March 23rd, 2024 at 17:54, Alexander Weps exander77@pm.me wr= ote: > > > One of the main purposes of struct tm is to calculate date and time, by= adding and substracting it's fields. > > > > > mktime cannot tell whether your non-normalized input was the result o= f > > > you starting with 01:00:02 and adding 1 hour (in which case, our > > > output does not reflect your intent) or of you starting with 3:00:02 > > > and subtracting 1 hour (in which case, our output does reflect your > > > intent). > > > > We are not adding hours here, your example is completely unrelated. > > > > We are adding or subtracting minutes that changes hours. > > > > tm_sec: 2 > > tm_min: 60 > > tm_hour: 1 > > > > vs > > > > tm_sec: 2 > > tm_min: 0 > > tm_hour: 2 > > > > And: > > > > tm_sec: 2 > > tm_min: 59 > > tm_hour: 1 > > > > vs > > > > tm_sec: 2 > > tm_min: -1 > > tm_hour: 2 > > > > AW > > > > On Saturday, March 23rd, 2024 at 16:31, Rich Felker dalias@libc.org wro= te: > > > > > On Sat, Mar 23, 2024 at 01:49:48PM +0000, Alexander Weps wrote: > > > > > > > I don't think time can go backwards by incrementing field under any= conditions. > > > > > > > > Going from: > > > > tm_sec: 2 > > > > tm_min: 60 > > > > tm_hour: 1 > > > > tm_mday: 31 > > > > tm_mon: 2 > > > > tm_year: 124 > > > > tm_wday: 0 > > > > tm_yday: 90 > > > > tm_isdst: -1 > > > > > > > > To: > > > > tm_sec: 1 > > tm_min: 59 > > tm_hour: 2 > > > > > > tm_sec: 2 > > > > tm_min: 0 > > > > tm_hour: 1 > > > > tm_mday: 31 > > > > tm_mon: 2 > > > > tm_year: 124 > > > > tm_wday: 0 > > > > tm_yday: 90 > > > > tm_isdst: 0 > > > > > > > > Seems to be plain wrong. I cannot come up with any argument for thi= s > > > > being correct under any conditions. > > > > > > The above broke-down time is 2:00:02, which does not exist on that da= y > > > as a normalized time. If interpreted as non-DST, it would be just a > > > couple seconds past the end of non-DST (1:59:59.99999..). If > > > interpreted as DST, it would be just under an hour before the start o= f > > > DST (3:00:00), which, after normalization, is 1:00:02 non-DST. > > > > > > mktime cannot tell whether your non-normalized input was the result o= f > > > you starting with 01:00:02 and adding 1 hour (in which case, our > > > output does not reflect your intent) or of you starting with 3:00:02 > > > and subtracting 1 hour (in which case, our output does reflect your > > > intent). > > > > > > > mktime was given a struct tm with uncertain STD/DST, it deduced it > > > > is STD and then thrown away 60 minute information. The minutes got > > > > reset from 60 to 0 and no other change was done. > > > > > > It did not deduce it was STD. It deduced it was non-normalized DST > > > rather than non-normalized STD (this is an arbitrary choice), then > > > normalized it and got STD. > > > > > > Rich