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: Lars Kindermann
Subject: [Octave-bug-tracker] [bug #50508] datenum() crashes for non-integer month arrays
Date: Thu, 16 Mar 2017 00:07:52 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:51.0) Gecko/20100101 Firefox/51.0

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

I attached a patch that hopefully handles fractional years correctly now. I
left the current code untouched for normal years and have added some lines
which are called just in case of fractional years.


   ## Lookup number of days since start of the current year.
   day += monthstart(mod (month-1,12) + 1) + 60;
 
+  ## Treat fractional years, by converting the fraction to days
+  if (any (year != fix (year)))
+    fracyear = year - floor (year);
+    year = floor (year);
+    day += fracyear .* (365 + is_leap_year (year+1));
+  endif
+  
   ## Add number of days to the start of the current year.  Correct
   ## for leap year every 4 years except centuries not divisible by 400.


Btw: It is not a good idea to test datenum using datestr as datestr calls
datenum itself. Better use datevec.


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

   2000.0000     12.0000     31.0000     23.0000     54.0000     43.7760
   2001.0000      1.0000     31.0000     23.0000     54.0000     43.7760
   2001.0000      2.0000     28.0000     23.0000     54.0000     44.6400
   2001.0000      3.0000     31.0000     23.0000     54.0000     44.6400
   2001.0000      4.0000     30.0000     23.0000     54.0000     44.6400
   2001.0000      5.0000     31.0000     23.0000     54.0000     44.6400
   2001.0000      6.0000     30.0000     23.0000     54.0000     44.6400
   2001.0000      7.0000     31.0000     23.0000     54.0000     44.6400
   2001.0000      8.0000     31.0000     23.0000     54.0000     44.6400
   2001.0000      9.0000     30.0000     23.0000     54.0000     44.6400
   2001.0000     10.0000     31.0000     23.0000     54.0000     44.6400
   2001.0000     11.0000     30.0000     23.0000     54.0000     44.6400
   2001.0000     12.0000     31.0000     23.0000     54.0000     44.6400
   2002.0000      1.0000     31.0000     23.0000     54.0000     44.6400


(file #40011)
    _______________________________________________________

Additional Item Attachment:

File name: datenumv3.diff                 Size:0 KB


    _______________________________________________________

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]