|
Message-ID: <20240325180208.GF4163@brightrain.aerifal.cx> Date: Mon, 25 Mar 2024 14:02:08 -0400 From: Rich Felker <dalias@...c.org> To: Alexander Weps <exander77@...me> Cc: musl@...ts.openwall.com Subject: Re: Broken mktime calculations when crossing DST boundary On Mon, Mar 25, 2024 at 09:42:53AM -0400, Rich Felker wrote: > On Mon, Mar 25, 2024 at 01:24:57PM +0000, Alexander Weps wrote: > > See below. > > > > AW > > > > > > On Monday, March 25th, 2024 at 14:13, Rich Felker <dalias@...c.org> wrote: > > > > > On Mon, Mar 25, 2024 at 12:55:28PM +0000, Alexander Weps wrote: > > > > > > > > If you take your test program and switch it to initialize with > > > > > tm_mday=31, then do -=1 instead of +=1, you'll find that it gives > > > > > 2011-12-29 01:00:00 -10 as well, only now it seems like the correct, > > > > > expected thing to happen. Any change to "fix" the case you're > > > > > complaining about would necessarily break this case. > > > > > > > > So (- day, +day): > > > > > > > > Musl: > > > > 2011-12-31 01:00:00 +14 > > > > 2011-12-29 01:00:00 -10 > > > > 2011-12-29 01:00:00 -10 > > > > > > > > Glibc: > > > > 2012-01-01 01:00:00 +14 > > > > 2011-12-31 01:00:00 +14 > > > > 2012-01-01 01:00:00 +14 > > > > > > > > Seems like musl doesn't even interpret the initial struct tm > > > > correctly in that case. It is off by day. > > > > > > > > Because December only had 30 days, 31s day after normalization is > > > > January 1st. > > > > > > > > > This is nonsense. December has a day 31, which you can clearly see > > > from the glibc output. For this particular year in this zone, with the > > > zone rule change, there are "only 30 days" in December, but they are > > > numbered 1-29 and 31, not 1-30. > > > > You confuse day of month which is represented in tm_mday with > > calendar day that is interpreted by strftime. > > > > You said to set tm_mday = 31, which would be January 1st after normalization. > > December 31s is 30th day of month represented as tm_mday = 30. > > OK, I meant tm_mday=31-1. Um, no, where did you get that idea? I just assumed you were right because I always forget which tm_* are off-by-1, but tm_mday is one-based not zero-based: int tm_mday; // day of the month -- [1, 31] (per the standard). So how did you end up getting the wrong thing? Are you even running the code you say you are? Rich
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.