bugGNU Octave - Bugs: bug #56190, localtime and gmtime ignore...

 
 

bug #56190: localtime and gmtime ignore nonscalar array elements

Submitter:  Andrew Janke <apjanke>
Submitted:  Sun 21 Apr 2019 10:56:49 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 23 Apr 2019 04:15:59 AM UTC, comment #4: 

I checked in a change (https://hg.savannah.gnu.org/hgweb/octave/rev/f6e59ee37fee) to emit an error when localtime or gmtime are called with a non-scalar argument.

Marking bug as fixed and closing report.

Rik <rik5>
Group administrator
Tue 23 Apr 2019 02:52:07 AM UTC, comment #3: 

Absolutely.  The for loop is more pedagogical since it is clearer what is happening.  But for your own use, arrayfun!

Rik <rik5>
Group administrator
Tue 23 Apr 2019 01:21:31 AM UTC, comment #2: 

I agree. If nobody's been asking for it before now, it's probably not a common use case, and the loop solution is fine. Adding an error message sounds fine.

You could one-liner it too with arrayfun, right?


loctimes = arrayfun(@localtime, time_data);


Andrew Janke <apjanke>
Mon 22 Apr 2019 04:48:05 PM UTC, comment #1: 

I also agree that silently choosing to ignore user input is not a good programming paradigm.

My first thought is that the extension to handle multiple inputs is not very common.  Hence, my leaning right now is that it is not worth spending core Octave programmer time on implementing it.  Rather, implement the solution to throw an error.

For users who really want this, they can run the for loop themselves


for i = 1: numel (time_data)
  loctimes(i) = localtime (time_data(i));
endfor



Rik <rik5>
Group administrator
Sun 21 Apr 2019 10:56:49 PM UTC, original submission:  

When you pass a nonscalar array of time values to localtime() or gmtime(), it seems that they ignore all elements past the first one. They still return a scalar structure containing scalar values.


octave:3> localtime(time .* [1 2 3])
ans =
  scalar structure containing the fields:
    usec =  514024
    sec =  27
    min =  53
    hour =  18
    mday =  21
    mon =  3
    year =  119
    wday = 0
    yday =  110
    isdst =  1
    gmtoff = -14400
    zone = EDT

octave:4> gmtime(time .* [1 2 3])
ans =
  scalar structure containing the fields:
    usec =  613960
    sec =  54
    min =  53
    hour =  22
    mday =  21
    mon =  3
    year =  119
    wday = 0
    yday =  110
    isdst = 0
    gmtoff = 0
    zone = UTC


When passed a nonscalar array, I would expect gmtime() and localtime() to do one of:

a) return a scalar struct with fields containing arrays the same size as the input
b) return a struct array the same size as the input, with each element containing scalar fields
c) raise an error

What do you think should be done here? I'm asking not so much because I have a use case for this, but I'd like guidance on how to handle the conversion from datetime objects to time structures in my Chrono package, and I don't think "silently ignore elements past the first" is the right thing to do.

Andrew Janke <apjanke>

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-04-23 rik5 StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2019-04-22 rik5 StatusNone Confirmed
    2019-04-22 rik5 Operating SystemMac OS Any

    Back to the top

    Powered by Savane 3.13-bb6a.
    Corresponding source code