delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1997/07/08/19:23:37

From: shankar AT viman DOT com (Shankar Ramamoorthy)
Subject: Beta 17.1 mktime() weirdness?
8 Jul 1997 19:23:37 -0700 :
Approved: cygnus DOT gnu-win32 AT cygnus DOT com
Distribution: cygnus
Message-ID: <33C2E1F7.7918.cygnus.gnu-win32@viman.com>
Mime-Version: 1.0
X-Mailer: Mozilla 3.01Gold (X11; I; SunOS 5.4 sun4m)
Original-To: gnu-win32 AT cygnus DOT com
Original-Sender: owner-gnu-win32 AT cygnus DOT com

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
shankar AT viman DOT com
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019