From owner-freebsd-questions Tue May 15 18: 5:33 2001 Delivered-To: freebsd-questions@freebsd.org Received: from mailf.telia.com (mailf.telia.com [194.22.194.25]) by hub.freebsd.org (Postfix) with ESMTP id C04F937B423 for ; Tue, 15 May 2001 18:05:28 -0700 (PDT) (envelope-from ertr1013@student.uu.se) Received: from d1o913.telia.com (d1o913.telia.com [195.252.44.241]) by mailf.telia.com (8.11.2/8.11.0) with ESMTP id f4G15Rt14202 for ; Wed, 16 May 2001 03:05:27 +0200 (CEST) Received: from ertr1013.student.uu.se (h185n2fls20o913.telia.com [212.181.163.185]) by d1o913.telia.com (8.8.8/8.8.8) with SMTP id DAA10070 for ; Wed, 16 May 2001 03:05:26 +0200 (CEST) Received: (qmail 56604 invoked by uid 1001); 16 May 2001 01:05:24 -0000 Date: Wed, 16 May 2001 03:05:24 +0200 From: Erik Trulsson To: Crist Clark Cc: freebsd-questions@FreeBSD.ORG Subject: Re: mktime(3) Bug? Message-ID: <20010516030524.A56457@student.uu.se> Mail-Followup-To: Crist Clark , freebsd-questions@FreeBSD.ORG References: <3B01CD18.6E725786@globalstar.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <3B01CD18.6E725786@globalstar.com>; from crist.clark@globalstar.com on Tue, May 15, 2001 at 05:43:04PM -0700 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Tue, May 15, 2001 at 05:43:04PM -0700, Crist Clark wrote: > Before I send in a PR, I wanted to make sure this was really a bug and > not some bizarre "feature" everyone already knew about but me. > > I noticed odd behavior when doing some conversions with date(1) (FreeBSD's > date(1) rewls for letting you do these kinds of conversions, BTW). Note what > happens when I cross a daylight savings time boundary (which was the 1st > of April for my timezone this year), > > $ date > Tue May 15 17:11:52 PDT 2001 > $ date -j -f %Y%m%d%H%M 200104020000 > Mon Apr 2 00:00:41 PDT 2001 > $ date -j -f %Y%m%d%H%M 200104010000 > Sat Mar 31 23:00:46 PST 2001 > > At first I thought it might be a conversion-only problem, but you get > the same thing if you _set_ the time across a DST boundary. Looking at > the date(1) code and reviewing the manpages, my best guess is that > mktime(3) uses the _current_ DST settings when setting the "target" > time. > > That would explain the behavior. And that, IMHO, is a bug. When a > user types that second command, he expects to see midnight on the > 1st, not 11 PM on the 31st. The DST of the "target" time should be > used by mktime(3), not the current one. This is especially true if > the user were setting the time rather than just displaying it. > > This is a bug, right? I don't think it is a bug. The date/time you give to date(1) is interpreted as being in your local timezone. What your second example shows is that 2001-04-01 00:00 PDT is the same time as 2001-03-31 23:00 PST which I believe is correct. It is not so much DST setting but *timezone* setting that matters. According to the manpage mktime(3) uses the *current* timezone when interpreting a date. It appears as if date(1) also interprets the date that way. If it is a bug it is at least buggy in a consistent, documented manner :-) One might argue about what is the best way to behave but I am fairly certain that date(1) is designed to behave as it does. (And I wouldn't be surprised if some standard mandates this behaviour.) -- Erik Trulsson ertr1013@student.uu.se To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message