bugGNU Octave - Bugs: bug #50673, datestr truncates fractional...

 
 

bug #50673: datestr truncates fractional minutes rather than rounding

Submitted by:  Luis Mendo <lmendo>
Submitted on:  Wed 29 Mar 2017 08:26:18 PM UTC  
 
Category: Octave FunctionSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Matlab Compatibility
Status: FixedAssigned to: None
Originator Name: Luis MendoOpen/Closed: Closed
Release: devOperating 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)

Sun 02 Apr 2017 10:35:33 PM UTC, comment #10:

Sorry, please ignore previous comment. All correct. Thanks again!

Luis Mendo <lmendo>
Sun 02 Apr 2017 10:34:06 PM UTC, comment #9:

Thank you both!

I've noticed that with the patched file

http://hg.savannah.gnu.org/hgweb/octave/file/68dbde0e670a/scripts/time/datestr.m

the result of 'datestr(datenum('1:00')-datenum('0:55'))' is now '12:05 AM'. I expected it would be '0:05 AM' (before the patch it was '0:04 AM', and Matlab gives '0:05 AM').

Luis Mendo <lmendo>
Sun 02 Apr 2017 04:12:53 AM UTC, comment #8:

Thanks Lars. I pushed it to the development branch here http://hg.savannah.gnu.org/hgweb/octave/rev/68dbde0e670a. Marking as fixed and closing report.

Rik <rik5>
Project Administrator
Thu 30 Mar 2017 10:48:20 PM UTC, comment #7:

I've attached a changeset. Hope formatting is correct. Had to learn about Mercurial basics first.

(file #40215)

Lars Kindermann <larskindermann>
Thu 30 Mar 2017 04:48:12 AM UTC, comment #6:

@Lars: I tested the patch and it works fine. Do you want to make it into a complete cset with a commit message and some BIST tests?

Rik <rik5>
Project Administrator
Thu 30 Mar 2017 01:25:20 AM UTC, comment #5:

I have attached a patch that rounds fractional seconds >= 0.9995 s to the next full second before formatting in datestr(). That also avoids printing 1000 ms in a FFF field.

(file #40202)

Lars Kindermann <larskindermann>
Wed 29 Mar 2017 11:26:49 PM UTC, comment #4:

typo...

I suggest datestr() and datevec() should stay compatible after any rounding...

Lars Kindermann <larskindermann>
Wed 29 Mar 2017 09:33:35 PM UTC, comment #3:

Perhaps datestr() should round the serial date to milliseconds before conversion. At the moment it looks pretty strange when including the milliseconds in the format:

But one should also consider that datestr() and datenum() should not give contradictory results.

Lars Kindermann <larskindermann>
Wed 29 Mar 2017 09:12:25 PM UTC, comment #2:

Not sure what Matlab's 'datestr' function does internally; its code is fairly complicated. But it seems to round. Compare Matlab:

and Octave:

Luis Mendo <lmendo>
Wed 29 Mar 2017 08:47:42 PM UTC, comment #1:

Definitely looks like rounding. datenum() calculates in days. See below where I calculate the expected difference in minutes.

So the question is whether datestr should use round or whether it should simply truncate the fractional part of minutes. The current behavior is to truncate as shown below.

One way to resolve this would be to test the equivalent code in Matlab. If they truncate results then Octave should too. If they round results then Octave should too.

Rik <rik5>
Project Administrator
Wed 29 Mar 2017 08:26:18 PM UTC, original submission:

This code

gives

instead of the expected

It seems to be a rounding issue with datestr, because

does give

Luis Mendo <lmendo>

 

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

Attach File(s):
   
   
Comment:
   

Attached Files
file #40215:  datestr.cset added by larskindermann (1KiB - application/octet-stream)
file #40202:  datestr.diff added by larskindermann (495B - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one

Digest:
   bug dependencies.

 

Carbon-Copy List
  • -unavailable- added by larskindermann (Posted a comment)
  • -unavailable- added by rik5 (Posted a comment)
  • -unavailable- added by lmendo (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 10 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Tue 20 Jun 2017 04:07:13 PM UTCmtmillerDependencies-=>bugs #51275 is dependent
    Sun 02 Apr 2017 04:12:53 AM UTCrik5StatusPatch Submitted=>Fixed
      Open/ClosedOpen=>Closed
    Thu 30 Mar 2017 10:48:20 PM UTClarskindermannAttached File-=>Added datestr.cset, #40215
    Thu 30 Mar 2017 04:48:12 AM UTCrik5StatusNeed Info=>Patch Submitted
    Thu 30 Mar 2017 01:25:20 AM UTClarskindermannAttached File-=>Added datestr.diff, #40202
    Wed 29 Mar 2017 08:47:42 PM UTCrik5Item GroupNone=>Matlab Compatibility
      StatusNone=>Need Info
      Release4.0.3=>dev
      Summary'datestr' gives wrong result. Possibly a rounding issue=>datestr truncates fractional minutes rather than rounding

    Back to the top


    Powered by Savane 3.1-cleanup1