From bug-request at octave dot org Sat Jan 7 20:35:45 2006 Subject: Re: etime in the new year From: Paul Kienzle To: Stefan van der Walt Cc: Keith Goodman , bug@octave.org Date: Sat, 7 Jan 2006 21:34:26 -0500 The datenum function in octave-forge handles leap years. You can use it directly: function elapsed = etime(t0,t1) elapsed = 86400*(datenum(t1)-datenum(t0)); end - Paul On Jan 7, 2006, at 6:00 PM, Stefan van der Walt wrote: > I saw formulas to calculate this thing in popular science magazines > before (Scientific American?). I'm sure there must be a relatively > simple way to accomplish this? > > Cheers > Stéfan > > On Tue, Jan 03, 2006 at 12:29:16PM -0600, Keith Goodman wrote: >> The function etime (elapsed time in seconds) returns an error when you >> compare times with different years. From the code >> >> if (t1 (1) != t0 (1)) >> error ("etime: can't handle timings over year boundaries yet"); >> endif >> >> Is that because it's painful to deal with leap years? What's the best >> fix? >> >> (1) Write a separate function to find if a year is a leap year. >> (2) Determine if a year is a leap year inside etime. >> (3) Bring over datenum from octave-forge and modify it to handle leap >> years and then use it for year, month, and day differences but not >> fractional parts of days. > > > > ------------------------------------------------------------- > 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 > ------------------------------------------------------------- > ------------------------------------------------------------- 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 -------------------------------------------------------------