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.0 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL 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 049C724A0A for ; Mon, 13 May 2024 14:17:55 +0200 (CEST) Received: (qmail 15393 invoked by uid 550); 13 May 2024 12:17:51 -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 14334 invoked from network); 13 May 2024 12:17:51 -0000 Date: Mon, 13 May 2024 08:18:04 -0400 From: Rich Felker To: musl@lists.openwall.com Message-ID: <20240513121802.GX10433@brightrain.aerifal.cx> References: <20240511212853.GS10433@brightrain.aerifal.cx> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] strptime(s, "%Y-%j", &tm) does not update month and day On Sun, May 12, 2024 at 09:54:13AM +0200, Petr Pisar wrote: > V Sat, May 11, 2024 at 05:28:54PM -0400, Rich Felker napsal(a): > > On Sat, May 11, 2024 at 05:24:59PM +0200, Petr Pisar wrote: > > > Hello, > > > > > > When debugging a libisds test failure with musl-1.2.5 > > > , I found that musl's > > > strptime() does not handle "%Y-%j" properly. It accepts the format, it parses > > > the input string, it returns a correct pointer past the input string, but it > > > does not update tm.tm_mon and tm.tm_mday fileds of the third argument. > > > > This is behaving as specified. Previously, the behavior was > > unspecified. POSIX has amended it for future issues as the resolution > > of https://austingroupbugs.net/view.php?id=1727 to read: > > > > The tm_yday member of the tm structure pointed to by tm shall be > > set to this number minus 1. > > > > strptime generally does not behave like mktime, doing > > normalizations/conversions. > > > I see. I thought that strptime() does the normalization. Reading > mktime() specification reveals it has a side effect of normalizing tm_yday > from tm_year, tm_mon, and tm_mday. > > However, I need the oposite and I cannot find any standard library function > for that. I will probaly resort to my own implementation with the drawback > of assumption that rules for leap years in Gregorian calendar won't change. That's certainly an option. I think you can also use mktime, though, if you want. Starting from a valid struct tm for Jan 1, then adding the tm_yday number to tm_mday, should get you most of the way there, short of timezone/dst mess. You could avoid that by using timegm, or if you assume POSIX-compatible time_t, just adding 86400*tm_yday to the time_t. Rich