From bug-octave-request at bevo dot che dot wisc dot edu Sun Dec 3 22:41:45 2000 Subject: possible error in time, ctime and related routines From: "John W. Eaton" To: Gerard van Dijnsen Cc: bug-octave at bevo dot che dot wisc dot edu Date: Sun, 3 Dec 2000 22:41:28 -0600 On 3-Dec-2000, Gerard van Dijnsen wrote: | I believe the output of time and ctime and related routines might be | offset by one hour. I am not too sure of myself, because the same bug | seems to exist in my linux distribution's date command. Perhaps I am | one who is entirely wrong here... If that is the case, sorry. As Trond says, I think you are confused by local time vs. UTC. The epoch is defined as 00:00:00 GMT 1 Jan 1970. | I have added one of my own functions here. I have not extensively tested | it, | but it seems to work ok. It converts dates in the format produced by the | clock function to seconds after the epoch. I believe it works ok, though | it | seems to be one hour off compared to octave (and the linux date | command), which | is how I found the bug (if it is one). Anyways, feel free to use the | code if | you find it useful! The function name sucks, so please think of somthing | more appropriate :-) The number of seconds since the epoch is given by the time function. It is a built-in function, so it will be much faster than your clck2sec function, and it will also not depend on the local time zone. And, I think you really do want the number of seconds since the epoch to be independent of the local time zone. Since Octave's clock function is just: function retval = clock () tm = localtime (time ()); retval = zeros (1, 6); retval(1) = tm.year + 1900; retval(2) = tm.mon + 1; retval(3) = tm.mday; retval(4) = tm.hour; retval(5) = tm.min; retval(6) = tm.sec + tm.usec / 1e6; endfunction your function undoes everything except the time zone conversion that happens in the call to localtime. BTW, Octave doesn't have mod function (it has rem instead). Does Matlab have mod now? If so, how is it different from rem? jwe ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------