bugGNU Octave - Bugs: bug #50508, datenum() crashes for non-integer...

 
 

bug #50508: datenum() crashes for non-integer month arrays

Submitted by:  Lars Kindermann <larskindermann>
Submitted on:  Fri 10 Mar 2017 05:44:33 PM UTC  
 
Category: Octave FunctionSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Unexpected Error
Status: FixedAssigned to: None
Originator Name: Open/Closed: Closed
Release: 4.2.1Operating System: Any

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

(Jump to the original submission Jump to the original submission)

Thu 16 Mar 2017 04:17:43 PM UTC, comment #14:

I pushed the patch under your name to the stable branch here (http://hg.savannah.gnu.org/hgweb/octave/rev/92d60bf45889). I added some BIST tests for fractional years as well.

I'm going to close this report, finally!

Rik <rik5>
Project Administrator
Thu 16 Mar 2017 04:07:52 AM UTC, comment #13:

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.

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

(file #40011)

Lars Kindermann <larskindermann>
Wed 15 Mar 2017 11:44:30 PM UTC, comment #12:

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

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

@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.

Rik <rik5>
Project Administrator
Wed 15 Mar 2017 11:33:29 PM UTC, comment #11:

I pushed the change for fractional months and the syntax

See http://hg.savannah.gnu.org/hgweb/octave/rev/a21f8372bb76.

Rik <rik5>
Project Administrator
Wed 15 Mar 2017 11:21:30 PM UTC, comment #10:

Sorry, there is still a glitch in datenum(), this time with fractional years:

or, better visible here:

The number of days in a year used in the calculation seems to ignore leap years.

Lars Kindermann <larskindermann>
Wed 15 Mar 2017 10:57:40 PM UTC, comment #9:

Yes, datestr() seems to use only the first entry in an array to auto-select the format. If time there is zero, all other rows also display the date only. I was fooled by that. Perhaps that should be changed in datestr(). datenum() works fine for me now.

Lars Kindermann <larskindermann>
Wed 15 Mar 2017 08:38:55 PM UTC, comment #8:

I think everything is working correctly. For the last example, it appears that datestr has chosen a different output format because the hour field is precisely aligned at 00 and 12. If I force datestr to use a long format (format 0) then this is what I get.

Rik <rik5>
Project Administrator
Wed 15 Mar 2017 01:58:40 PM UTC, comment #7:

this works fine now:

add one hour

that looks good, too, same with 11 hours

but what happens with 12 hours on non leap years?

I slowly understand why matlab people decided to not support fractional month but just round it down...

Lars Kindermann <larskindermann>
Tue 14 Mar 2017 08:15:09 PM UTC, comment #6:

I'm attaching a proposed changeset. Please verify that it works for the corner cases you have in mind.

(file #40005)

Rik <rik5>
Project Administrator
Mon 13 Mar 2017 09:19:02 PM UTC, comment #5:

@Lars: Let me try. I know exactly where the code is that I want to change.

Rik <rik5>
Project Administrator
Mon 13 Mar 2017 08:58:42 PM UTC, comment #4:

@Rik Are you already working on it or shall I give it a try?

Lars Kindermann <larskindermann>
Mon 13 Mar 2017 03:14:42 PM UTC, comment #3:

Confirmed. The part of the code that exands all inputs to common size occurs after the fractional month calculation. The program flow should probably be:

1) Validate inputs
2) Convert to common format (strings->datevec) and common size
3) Perform datenum calculation

Rik <rik5>
Project Administrator
Mon 13 Mar 2017 11:31:00 AM UTC, comment #2:

datenum() still crashes for fractional month using the other calling convention: datenum(year,month,day):

+verbose+

>> datestr(datenum(2000:2003,2,1))

ans =

01-Feb-2000
01-Feb-2001
01-Feb-2002
01-Feb-2003
-verbose-

works, but

+verbose+

>> datestr(datenum(2000:2004,2.5,1))

error: fracmonth(4): out of bound 1
error: called from
datenum at line 135 column 14
-verbose-

Lars Kindermann <larskindermann>
Sun 12 Mar 2017 06:30:09 PM UTC, comment #1:

I decided to fix this on the stable release since Octave shouldn't be generating errors for legal inputs. I checked in a changeset here (http://hg.savannah.gnu.org/hgweb/octave/rev/afa48a26e684) that adds support for fractional months and some specific tests for fractional months and leap years.

Rik <rik5>
Project Administrator
Fri 10 Mar 2017 05:44:33 PM UTC, original submission:

datenum() allows integer and fractional month inputs:

However, if fed with an array of dates, it crashes when any month value is not integer:

This patch solves the problem:

Remark: there is some incompatibility with matlab which simply trunctates fractional month while octave adds respective days. See Bug #50493 comment #4 for details.

Lars Kindermann <larskindermann>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

Attached Files
file #40011:  datenumv3.diff added by larskindermann (742B - text/x-patch)
file #40005:  dnum.cset added by rik5 (3KiB - application/octet-stream)
file #39965:  datenum.diff added by larskindermann (734B - text/x-patch - patch for datenum())

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by rik5 (Posted a comment)
  • -unavailable- added by larskindermann (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 11 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Thu 16 Mar 2017 04:17:43 PM UTCrik5StatusPatch Submitted=>Fixed
      Open/ClosedOpen=>Closed
    Thu 16 Mar 2017 04:07:52 AM UTClarskindermannAttached File-=>Added datenumv3.diff, #40011
    Tue 14 Mar 2017 08:15:09 PM UTCrik5Attached File-=>Added dnum.cset, #40005
      StatusConfirmed=>Patch Submitted
    Mon 13 Mar 2017 03:14:42 PM UTCrik5StatusFixed=>Confirmed
      Open/ClosedClosed=>Open
    Sun 12 Mar 2017 06:30:09 PM UTCrik5StatusNone=>Fixed
      Open/ClosedOpen=>Closed
      Releasedev=>4.2.1
    Fri 10 Mar 2017 05:44:33 PM UTClarskindermannAttached File-=>Added datenum.diff, #39965

    Back to the top


    Powered by Savane 3.1-cleanup1