home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!gatech!usenet.ins.cwru.edu!agate!linus!linus.mitre.org!mbunix.mitre.org!jrv
- From: jrv@mbunix.mitre.org (Van Zandt)
- Subject: Re: Finding the number of days between two dates
- Message-ID: <1993Jan5.172933.16737@linus.mitre.org>
- Sender: news@linus.mitre.org (NONUSER)
- Nntp-Posting-Host: mbunix.mitre.org
- Organization: The MITRE Corp., Bedford, Ma.
- References: <1992Dec9.011317.26944@klaava.Helsinki.FI> <1992Dec10.181940.10135@linus.mitre.org> <27537@sybase.sybase.com>
- Date: Tue, 5 Jan 1993 17:29:33 GMT
- Lines: 46
-
- In article <27537@sybase.sybase.com> venky@sybase.com (Venky) writes:
- >In article <1992Dec10.181940.10135@linus.mitre.org> jrv@truth.mitre.org (Van Zandt) writes:
- >>In article <1992Dec9.011317.26944@klaava.Helsinki.FI> wirzeniu@klaava.Helsinki.FI (Lars Wirzenius) writes:
- >>>pjh@cs.tut.fi (Haavisto Petri) writes:
- >>>>1. When using mktime(), is it necessary to set all fields of the
- >>>>tm-structure to correct values?
- >>>
- >>>No. tm_wday and tm_yday (and tm_isdst?) are computed by mktime based
- >>>on the other fields. In fact, the required fields do not have to be
- >>>in their required fields either, mktime normalises them.
- >>
- >>The Borland docs claim their mktime() normalizes those values, but
- >>it doesn't. (I'm posting a separate msg on that.) My "Osborne McGraw-Hill
- >>C the Complete Reference" doesn't mention the normalization. Is it required
- >>by the standard?
- >>
- >> - Jim Van Zandt <jrv@mitre.org>
- >
- >
- > ANSI Standard requires that tm_wday and tm_yday be computed
- > based on the other fields in the 'struct tm'. I have seen
- > that most versions of Unix do not support that, though.
- >
- > The latest HP-UX 9.0 however, has got this fix and works
- > well. I should know.....
- > Venky
-
- I have posted a program (julcal) to alt.sources which converts between
- a struct tm and a Julian day number (number of days since Jan 1, 4713 BC).
- Clearly, this solves the days-between-two-dates problem. It also does
- the normalization and calculation of day-of-week and day-of-year (that is,
- calculation of tm_wday and tm_yday). Unlike mktime(), it also works for
- dates in the distant past (before 1/1/1970, 1/1/1900, or even 4700 BC, with
- user selectable date for transition between Julian and Gregorian calendars.
-
- I wouldn't trust mktime() without testing it first.
- The julcal package includes a test program which compares the normalization
- and calculation of tm_wday and tm_yday with those found by mktime().
- Since I found errors in both Sun and Borland implementations of mktime(),
- the test program attempts to show which has the error. Therefore, you
- can use the test program to test your mktime(). I'd be interested in
- learning of other implementation bugs, but of course messages to
- your customer support people may do you more good :-).
-
- - Jim Van Zandt <jrv@mitre.org>
-
-