Article View: comp.std.c
Article #4160mktime murk
From: Paul Eggert
Date: Tue, 03 Oct 1995 03:20
Date: Tue, 03 Oct 1995 03:20
51 lines
2498 bytes
2498 bytes
msb@sq.com (Mark Brader) writes:
> I certainly agree that the wording should specify this effect more clearly.
The mktime wording needs other clarification, too. It's not clear how
mktime is supposed to adjust tm_isdst. I submitted Defect Report #136
about this, and got an answer for one particular case, but there are
others that I hadn't thought of when I wrote that defect report.
For example, this program asks for 1996-01-01 00:00:00 daylight savings time:
#include <time.h>
#include <stdio.h>
int main()
{
struct tm tm;
tm.tm_year = 1996 - 1900; tm.tm_mon = 1 - 1; tm.tm_mday = 1;
tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
tm.tm_isdst = 1;
mktime (&tm);
printf ("%d-%.2d-%.2d %.2d:%.2d:%.2d isdst=%d\n",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_isdst);
return 0;
}
Assuming US Pacific rules, which use standard time on New Year's Day,
should this program output
(1) `1995-12-31 23:00:00 isdst=0', or
(2) `1995-01-01 00:00:00 isdst=0'?
Which output is correct, and why?
One interpretation is that mktime should use a non-negative tm_isdst to
decide whether the time is standard or daylight, regardless of whether
what kind of time was actually used. This interpretation yields (1)
above. It's perhaps the most common interpretation in practice, but it
leads to further ambiguities -- e.g. how much should mktime adjust
1989-01-01 00:00:00 with tm_isdst=1 in Newfoundland, which used a
2-hour DST offset in summer 1988 and a 1-hour DST offset in summer
1989?
Another interpretation is that mktime should use tm_isdst as a
tie-breaker: that is, if the asked-for time must be standard then set
tm_isdst to 0; if it must be daylight then set it to 1; otherwise, the
time is ambiguous, and use tm_isdst to decide between standard and
daylight. This interpretation yields (2) above. This rule is simpler
and does not lead to ambiguities, but it's less often used.
As far as I can tell, the standard is murky enough to allow either
interpretation.
Technical Details
Message-ID:
<44qa5g$qj8@tattoo.twinsun.com>Path:
arc1-ca.pugleaf.net!delphi.cs.ucla.edu!twinsun!not-for-mailReferences:
<44mio5$63n@mark.ucdavis.edu> <812657476snz@genesis.demon.co.uk> <1995Oct2.215246.371@sq.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!delphi.cs.ucla.edu!twinsun!not-for-mail From: eggert@twinsun.com (Paul Eggert) Newsgroups: comp.std.c Subject: mktime murk Date: 2 Oct 1995 20:20:16 -0700 Organization: Twin Sun Inc, El Segundo, CA, USA Message-ID: <44qa5g$qj8@tattoo.twinsun.com> References: <44mio5$63n@mark.ucdavis.edu> <812657476snz@genesis.demon.co.uk> <1995Oct2.215246.371@sq.com> NNTP-Posting-Host: tattoo.twinsun.com