bugGNU Octave - Bugs: bug #60107, datenum : 1 day missing from...


bug #60107: datenum : 1 day missing from output?

Submitted by:  Paul Netsaver <netsaver>
Submitted on:  Wed 24 Feb 2021 12:38:46 AM UTC  
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Confirmed Assigned to:  None
Originator Name:  Netsaver Paul Open/Closed:  Open
Release:  6.2.0 Operating System:  Any

Add a New Comment (Rich Markup)

You are not logged in

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


Wed 24 Feb 2021 11:43:48 PM UTC, comment #5: 

soryy, I intended:

> datestr(datenum('00','yy'),'yy') = '00' (Matlab)

Paul Netsaver <netsaver>
Wed 24 Feb 2021 11:41:27 PM UTC, comment #4: 

Here's my five cents:

a) you are write, 'MM' in datenum format stands for minutes. Anyway, for me it was misleading that 'YY' and 'DD' are not case sensitive and that symbols for datenum arrays are: [Y,M,D,H,MN,S]. But it's ok as it is stated in Matlab doc.

b) I cannot agree on convention: if a date is valid with years only, should be completed with valid month/day.
According to your point, should be added a convention by which '2000' stands for '2000 Jan 0' where this is an alias for '1999 Dec 31'...
The point is that a virtual zero-day of 2000 cannot belong by design to 2000 for 'datestr' and to 1999 for 'datenum', otherwise we get:

datestr(datenum('00','yy'),'yy') = '99' (Octave)
datestr(datenum('00','yy'),'yy') = '99' (Matlab)

while on contrary:
datenum(datestr(730485)) = 730485 (Octave/Matlab)

Moreover, if we want Matlab-Octave compatible code, we have to consider 'yy' an invalid date, or at least add a control for transforming: 'yy' to 'yy0101'.

datenum("2000 Jan 1","yyyy mmm dd")-datenum("2000","yyyy")
ans = 0 (Matlab)
ans = 1 (Octave)

datenum("2000 Jan 0","yyyy mmm dd")
error: datevec: DATE not parsed correctly with given format

Paul Netsaver <netsaver>
Wed 24 Feb 2021 08:46:07 PM UTC, comment #3: 

matlab does a few other braindead stuff on this topic too, btw (which I hope don't get "fixed" in octave).

E.g. datestr(-2) returns year 9999 instead of -1

Tasos Papastylianou <tpapastylianou>
Wed 24 Feb 2021 08:38:52 PM UTC, comment #2: 

For what it's worth:

a) The original submission has a bug. The format string should be 'mm' not 'MM'. 'MM' stands for minutes, not months, and therefore reports zero minutes. The same behaviour is seen in matlab too (so your example actually displays '00' in matlab too). Months are 1-indexed, not 0-indexed, in both matlab and octave.

b) As for the main 'bug', at the end of the day, it's behaviour that deviates from matlab, I agree. But. The octave version actually makes more sense. I would have been tempted to report this to matlab as a bug instead.

I get that at the end it's a design decision, but in my mind it makes perfect sense that the "zeroth day of 2000" is actually 12 Dec 1999, such that offsets relative to this date can be honoured. So, I would expect "2000 Jan 31st" - "2000" to output 31, not 30. If I wanted 30 I would specify "2000-01-31" - "2000-01-01" explicitly.

I understand matlab using the date 12th Dec of year -0001 arbitrarily as 0th of 0, 0000, but even that causes more trouble than not. (especially since the year -1 is actually 2BC). I actually found it more meaningful for "0000-01-01" - 1 to output "-0001-12-31" (I see that this has now been updated/changed in octave too, alas.)

Tasos Papastylianou <tpapastylianou>
Wed 24 Feb 2021 05:24:16 PM UTC, comment #1: 

Confirmed.  Changing the OS to "Any" as I see the same behavior on Linux.

This certainly seems like an off-by-1 sort of error.  Here is a slightly simpler example

datenum ('2000', 'YYYY')
ans = 730485
octave:29> datevec (ans)
ans =

   1999     12     31      0      0      0

So datenum is returning 12/31/1999 when it should return 1/1/2000.

Rik <rik5>
Project Administrator
Wed 24 Feb 2021 12:38:46 AM UTC, original submission:  

Original code:
dn = datenum('00','YY');
ds = datestr(dn,'YY');
ds = datestr(dn+1,'YY');
ds = datestr(dn+1,'YY-MM-DD');

dn = 730485
ds = '99'              % should be back to '00'
ds = '00'
ds = '00-00-01'        % should have positive months

dn = 730486
ds = '00'
ds = '00-01-01'
ds = '00-01-02'

it seems Octave computes datenum 1-day less; moreover, months start from 00, not 01.

Paul Netsaver <netsaver>


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

Attach Files:

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 tpapastylianou (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by netsaver (Submitted the item)
  • -email is unavailable- added by netsaver

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

    Only project members can vote.




    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-02-24 rik5 StatusNone => Confirmed
        Operating SystemMicrosoft Windows => Any
    2021-02-24 netsaver Carbon-Copy- => Added netsaverpaul@gmail.com

    Back to the top

    Powered by Savane 3.6