mktime(&now) problem

mktime(&now) problem

Post by John R MacMill » Tue, 07 Oct 1997 04:00:00



[ I've cross-posted this to comp.unix.sco.programmer, and directed
  followups there. ]

|I find that adding ANY number of days to now.tm_mday *works*, but if
|I subtract enough days from tm_mday to preceed the first of the month,
|the routine: (void) mktime(&now);
|just can't figure out the correct date.
|
|Is this a limitation on mktime, or perhaps on SCO's version of mktime?

It's not a limitation on mktime().  There is a bug in mktime() on
OpenServer Release 5 up to and including 5.0.4, I believe, that may
be causing the behaviour you are seeing.  There is a fix for it,
TLS600, available from ftp.sco.com/TLS or their web site.
--
To reply by mail, please remove "mail." from my address

 
 
 

mktime(&now) problem

Post by Brian McCaule » Tue, 07 Oct 1997 04:00:00



> time(&longtime);
> now = *localtime(&longtime);

> and attempting to fiddle with the date by adding/subtracting values
> to/from now.tm_mday;

Why?  Wouldn't it be simpler to manipuate longtime directly?

Quote:> I find that adding ANY number of days to now.tm_mday *works*,

  ^^^^^^
You should not employ such empiricism.  That way lies unportable code.

Quote:> but if I subtract enough days from tm_mday to preceed the first of
> the month, the routine: (void) mktime(&now); just can't figure out
> the correct date.
>Is this a limitation on mktime, or perhaps on SCO's version of
> mktime?

My man page I've seen for mktime() (GNU) says now.tm_day is in the
range 1-31.  By implication the behaviour of mktime() for other values
of tm_day is undefined.  AFAIK *that* is the limitation on mktime().

--

 .  _\\__[oo       from       | Phones: +44 121 471 3789 (home)

.  l___\\    /~~) /~~[  /   [ | PGP-fp: D7 03 2A 4B D8 3A 05 37...
 # ll  l\\  ~~~~ ~   ~ ~    ~ | http://wcl-l.bham.ac.uk/~bam/


 
 
 

mktime(&now) problem

Post by Jim Pazaren » Tue, 07 Oct 1997 04:00:00


I am fetching the current date:

time(&longtime);
now = *localtime(&longtime);

and attempting to fiddle with the date by adding/subtracting values
to/from now.tm_mday;

I find that adding ANY number of days to now.tm_mday *works*, but if
I subtract enough days from tm_mday to preceed the first of the month,
the routine: (void) mktime(&now);
just can't figure out the correct date.

Is this a limitation on mktime, or perhaps on SCO's version of mktime?

 
 
 

mktime(&now) problem

Post by John R MacMill » Thu, 09 Oct 1997 04:00:00


|> and attempting to fiddle with the date by adding/subtracting values
|> to/from now.tm_mday;
|
|Why?  Wouldn't it be simpler to manipuate longtime directly?

It may be simpler, but it doesn't work around daylight savings time
changes (since not all days have 24 hours), and it's not guaranteed
to work at all on non-UNIX machines (since mktime() is a Standard C
function where time_t are not required to be in seconds, but POSIX
says explicitly that it's seconds since the Epoch).

That's what mktime() is _for_, to handle such picky bits.

|My man page I've seen for mktime() (GNU) says now.tm_day is in the
|range 1-31.  By implication the behaviour of mktime() for other values
|of tm_day is undefined.  AFAIK *that* is the limitation on mktime().

No, the purpose of mktime() is to normalise a struct tm, and it is
allowed to be called with values outside the normal range.
--
To reply by mail, please remove "mail." from my address

 
 
 

1. mktime & TimeZones

Following the directions in the man page for mktime, I set tm_isdst
to "-1", for self determination of daylight savings.  It seems to
choose the wrong one.  What gives?  Is there a patch?  We can't
distribute data with incorrect time stamps.

--Chris

2. PPP & SSH & VPN

3. &&&&----Looking for a unix shell------&&&&&

4. NFS cannot start

5. mktime fixes problem

6. HOW TO REMOVE bad route

7. mktime + settimeofday problem?!

8. DHCP

9. mktime very simple problem.

10. ppp && PPPoE && ADSL && net && buffer(s)

11. 没有人用中文吗?

12. &&&&&& SUGGESTION ??? &&&&&&&&

13. problems with (Apache && Solaris && mod_perl)