Subject: Beta 17.1 mktime() weirdness?
From: [email-masked] (Shankar Ramamoorthy)

8 Jul 1997 19:23:37 -0700
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Mozilla 3.01Gold (X11; I; SunOS 5.4 sun4m)
Original-To: [email-masked]
Original-Sender: [email-masked]

Does anybody know of any weirdness with mktime in Beta 17.1?

I find that
  x != mktime(localtime(&x))
which is true on my SPARC Solaris 2.x box.
Contrarywise,
  x == mktime(gmtime(&x))
under Cygwin B 17.1 which not true under Solaris.

An example x is 812556000.

The problem seems to be that mktime(struct tm *tm) thinks that the
*tm is a GMT time, whereas it should be treated as a local time. It
doesn't matter what I set tm_isdst in the struct tm to, it always
returns the same value.

Here's a simple C++ program to illustrate the problem:
#include <iostream.h>
#include <sys/time.h>
#include <time.h>

int main ()
{
  struct tm tmTimeGMT, tmTimeLocal, *tmTimeP;
  time_t    tTimeRef, tTimeGMT, tTimeLocal;

  tTimeRef = 812556000;
  tmTimeP = localtime(&tTimeRef);
  memcpy((void *) &tmTimeLocal, (void *) tmTimeP, sizeof(tmTimeLocal));
  tmTimeP = gmtime(&tTimeRef);
  memcpy((void *) &tmTimeGMT, (void *) tmTimeP, sizeof(tmTimeGMT));
  
  tTimeLocal = mktime(&tmTimeLocal);
  tTimeGMT   = mktime(&tmTimeGMT);

  cout << "Reference time was <" << tTimeRef   << ">\n";
  cout << "Local     time was <" << tTimeLocal << ">\n";
  cout << "GMT       time was <" << tTimeGMT   << ">\n";

  exit(0);
  
} // main()

On Solaris I get:
Reference time was <812556000>
Local     time was <812556000>
GMT       time was <812584800>

Under Cygwin Beta 17 (under NT 4.0) I get:
Reference time was <812556000>                         
Local     time was <812530800>                         
GMT       time was <812556000> 

Maybe its fixed in Beta 18? But I cant really switch right now.
Any work around?

Shankar
[email-masked]
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".