octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #50508] datenum() crashes for non-integer mont


From: Rik
Subject: [Octave-bug-tracker] [bug #50508] datenum() crashes for non-integer month arrays
Date: Wed, 15 Mar 2017 19:44:30 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0

Follow-up Comment #12, bug #50508 (project octave):

The problem with fractional years was present in 4.2.1 so at least we haven't
introduced anything new with our changes.  I'm sure this is related to some
odd shifting of the start of the year.  The code is


  ## Set start of year to March by moving Jan. and Feb. to previous year.
  ## Correct for months > 12 by moving to subsequent years.
  year += ceil ((month-14)/12);

  ## Lookup number of days since start of the current year.
  day += monthstart(mod (month-1,12) + 1) + 60;

  ## Add number of days to the start of the current year.  Correct
  ## for leap year every 4 years except centuries not divisible by 400.
  day += 365*year + floor (year/4) - floor (year/100) + floor (year/400);


Whatever we are doing, I would expect it to cause problems for Jan. and Feb. 
Indeed, that is what this code shows.


datestr (datenum (2000.99999, 1:14, 1))
ans =

30-Dec-2000 23:54:44
30-Jan-2001 23:54:44
28-Feb-2001 23:54:44
31-Mar-2001 23:54:44
30-Apr-2001 23:54:44
31-May-2001 23:54:44
30-Jun-2001 23:54:44
31-Jul-2001 23:54:44
31-Aug-2001 23:54:44
30-Sep-2001 23:54:44
31-Oct-2001 23:54:44
30-Nov-2001 23:54:44
31-Dec-2001 23:54:44
31-Jan-2002 23:54:44

datestr (datenum (2001.99999, 1:14, 1))
ans =

31-Dec-2001 23:54:44
31-Jan-2002 23:54:44
28-Feb-2002 23:54:44
31-Mar-2002 23:54:44
30-Apr-2002 23:54:44
31-May-2002 23:54:44
30-Jun-2002 23:54:44
31-Jul-2002 23:54:44
31-Aug-2002 23:54:44
30-Sep-2002 23:54:44
31-Oct-2002 23:54:44
30-Nov-2002 23:54:44
31-Dec-2002 23:54:44
31-Jan-2003 23:54:44


@Lars: Do you want to take a look at this one?  It looks to me like in the
lookup for number of days since the start of the current year the constant +60
needs to be +61 for leap years.


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?50508>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]