octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #60671] Wrong result when subtracting one mont


From: Georg Wiora
Subject: [Octave-bug-tracker] [bug #60671] Wrong result when subtracting one month from 31-MON-YEAR date
Date: Tue, 25 May 2021 11:53:02 -0400 (EDT)
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:88.0) Gecko/20100101 Firefox/88.0

Follow-up Comment #2, bug #60671 (project octave):

I added a file with a suggested fix, but I am not shure if this is allways the
intended behaviour. Also I do not know the matlab behaviour, but Matlab
compatibility should be provided. My fix uses EOMday() function to check if
the resulting day is beyond end of previous month. This leads to the situation
that some operations with different dates may produce the same result date,
but at least the result is allways in the previous month:

>> datestr(addtodate(datenum('31-Dec-2020'),-1,'month'))
ans = 30-Nov-2020
>> datestr(addtodate(datenum('30-Dec-2020'),-1,'month'))
ans = 30-Nov-2020
>> datestr(addtodate(datenum('29-Dec-2020'),-1,'month'))
ans = 29-Nov-2020 


Matlab manual states about adding negative numbers:

_Adding a negative quantity to the indicated date field rolls back the
calender on the indicated field. If the addition causes the field to roll
back, MATLAB adjusts the next less significant fields accordingly._

This does not make absolutely clear what happens when adding negative
numbers.
Can someone prove the Matlab behaviour with these test cases?

TODO: Add discussed situations as test cases to bug fixed file.


    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?60671>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]