home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19268 < prev    next >
Encoding:
Text File  |  1993-01-05  |  2.8 KB  |  59 lines

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