From bug-octave-request at bevo dot che dot wisc dot edu Tue Jan 4 10:48:14 2000 Subject: Still problems with time func since y2k (win95/gnuwin32) From: "John W. Eaton" To: Rolf Fabian Cc: "'bug-octave UWISC'" Date: Tue, 4 Jan 2000 10:48:35 -0600 (CST) On 4-Jan-2000, Rolf Fabian wrote: | yesterday, I've already reported problems with clock.m (returning | year 1970 instead of 2000) on my win95/gnuwin32 installation since | Jan. 1st 2000. I've got a reply from jwe, that it's highly unlikely | to be an octave-bug because clock() simply calls ,localtime( time() | )'. | | Now I'm convinced, that the problem comes from ,time()' call, which | should return the number of seconds since 1970 (UNIX epoch). The | number returned by ,time()' is incorrect and by far too small !! | | Please have a look at the following log | | :> version | ans=2.0.13 #win95/gnuwin32-b20 | :> system('date'); LT=localtime(TIME=time()), TIME, CLOCK=clock() | Tue Jan 4 16:35:43 2000 | | LT = | { | usec = 8.0900e+05 | year = 70 | mon = 0 | mday = 25 | sec = 22 | min = 22 | wday = 0 | hour = 10 | isdst = 0 | yday = 24 | } | | TIME = 2.1073e+06 | CLOCK = | 1970.0000 1.0000 25.0000 10.0000 22.0000 22.8090 | | Because as a ,rule of thumb' an (average) year has about pi*1e7 | seconds , the output of TIME=time() octave built-in func. is | obviously much too small and seems to be responsible for the | problems observed. Right, it looks like the system library's time function is returning the wrong thing. Octave's time function does just DEFUN_DLD (time, , , "time ()\n\ \n\ Return current time. On Unix systems, this is the number of\n\ seconds since the epoch.") { time_t now; double fraction = 0.0; #if defined (HAVE_GETTIMEOFDAY) struct timeval tp; #if defined (GETTIMEOFDAY_NO_TZ) gettimeofday (&tp); #else gettimeofday (&tp, 0); #endif now = tp.tv_sec; fraction = tp.tv_usec / 1e6; #else now = time (0); #endif return (double) now + fraction; } Which I believe is the correct way to use these functions. I suspect that gettimeofday is returning something invalid on your system (you have a nonzero microsecond field in your localtime struct, so it seems likely that your binary was compiled with HAVE_GETTIMEOFDAY defined). Probably the bug is either in the version of the cygwin library you are using, or in the Windows system calls (if any, I haven't checked) that it depends on to implement the gettimeofday function. jwe ----------------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.che.wisc.edu/octave/octave.html How to fund new projects: http://www.che.wisc.edu/octave/funding.html Subscription information: http://www.che.wisc.edu/octave/archive.html -----------------------------------------------------------------------