Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 15 May 2001 18:26:33 -0700
From:      "Crist Clark" <crist.clark@globalstar.com>
To:        Erik Trulsson <ertr1013@student.uu.se>
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: mktime(3) Bug?
Message-ID:  <3B01D749.B6848B19@globalstar.com>
References:  <3B01CD18.6E725786@globalstar.com> <20010516030524.A56457@student.uu.se>

next in thread | previous in thread | raw e-mail | index | archive | help
Erik Trulsson wrote:
> 
> 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.

I guess an interesting  question is, is there really such a thing as 
2001-04-01 00:00 PDT? (Although there is definately a 2001-04-02 01:00 PST.)

> 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.

But not everything does...
 
> 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.)

This is exactly why I asked. However, it seems buggy to me since I would
think that the behavior defies the expectation of the vast majority of
users. Maybe the bug is in date(1) and not mktime(3); I would not be surpised
if a standard called for it either.

I am not also sure if it is all that consistent. I ran into the issue when 
I was playing with some file modification times. When I 'ls -l' a directory,
the times on the files for those from before Apr 1 are correct. That is,
since they were created during PST, the times are still given as PST. When
my current timezone shifts to PDT, files that were made in PST still show
the correct PST time. Why would I not expect the same behavior from date(1)?
When I give date(1) a time that occurs in PST, why shouldn't it interpret
it as a PST time?
-- 
Crist J. Clark                                Network Security Engineer
crist.clark@globalstar.com                    Globalstar, L.P.
(408) 933-4387                                FAX: (408) 933-4926

The information contained in this e-mail message is confidential,
intended only for the use of the individual or entity named above.  If
the reader of this e-mail is not the intended recipient, or the employee
or agent responsible to deliver it to the intended recipient, you are
hereby notified that any review, dissemination, distribution or copying
of this communication is strictly prohibited.  If you have received this
e-mail in error, please contact postmaster@globalstar.com

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3B01D749.B6848B19>