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

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

[Octave-bug-tracker] [bug #50493] datetick crashes on certain date range


From: Lars Kindermann
Subject: [Octave-bug-tracker] [bug #50493] datetick crashes on certain date ranges
Date: Fri, 10 Mar 2017 07:24:23 -0500 (EST)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:51.0) Gecko/20100101 Firefox/51.0

Follow-up Comment #3, bug #50493 (project octave):

I attached an updated patch that fixes it in all calls to datenum() but the
real problem might rather be datenum() itself which shows pretty inconsistent
behaviour for non integer inputs:



>> datestr(datenum([2017 1 1]))
ans = 01-Jan-2017


>> datestr(datenum([2017 1 1; 2017 1 1]))
ans =

01-Jan-2017
01-Jan-2017


>> datestr(datenum([2017 1.5 1]))
ans = 16-Jan-2017 12:00:00


>> datestr(datenum([2017 1 1; 2017 1.5 1]))
error: monthstart(1.5): subscripts must be either integers 1 to (2^63)-1 or
logicals
error: called from
    datenum at line 154 column 9


>> datestr(datenum([2017 1.5 1; 2017 1.5 1]))
error: datenum: operator *: nonconformant arguments (op1 is 2x1, op2 is 2x1)
error: called from
    datenum at line 137 column 11



Probably datenum() should be fixed instead as non-integer years and days
always work fine. Non-int month also work for a single date but fail for a
date array. 

For compatibility, could somebody check how Matlab's datenum() behaves for
non-integer inputs?


However, the attached updated patch avoids all non-integer datenum() calls in
datetick() and sets ticks to more sane positions (midnight,1st of month) than
calls for a fixed datenum would (noon, arbitrary day):



# HG changeset patch
# User larskindermann
# Date 1489148123 -3600
#      Fri Mar 10 13:15:23 2017 +0100
# Node ID 10a22466008eae6356116ebef7597c74e747f4da
# Parent  99ee4dd83ceb49edcc6d6e76e3f9188613bde7a5
fix range bugs in datetick.m

diff -r 99ee4dd83ceb -r 10a22466008e scripts/plot/appearance/datetick.m
--- a/scripts/plot/appearance/datetick.m        Wed Mar 08 21:11:54 2017 -0800
+++ b/scripts/plot/appearance/datetick.m        Fri Mar 10 13:15:23 2017 +0100
@@ -219,15 +219,19 @@
         minmonth = ifelse (minmonth == 0, 1, minmonth);
         maxmonth = sep * ceil (maxmonth / sep);
         rangemonth = (minmonth:sep:maxmonth)';
+        tickdays = round(1 + 28 * mod(rangemonth,1));
         ticks = datenum ([repmat(minyear, size(rangemonth)), ...
-                          rangemonth, ...
-                          ones(size (rangemonth))]);
+                          floor(rangemonth), ...
+                          tickdays]);
       else
         sep = __calc_tick_sep__ (minyear, maxyear);
         minyear = sep * floor (minyear / sep);
         maxyear = sep * ceil (maxyear / sep);
         rangeyear = (minyear:sep:maxyear)';
-        ticks = datenum ([rangeyear, ones(rows(rangeyear),2)]);
+        tickmonth = round(1 + 12 * mod(rangeyear,1));
+        ticks = datenum ([floor(rangeyear), ... 
+                          tickmonth, ...
+                          ones(rows(rangeyear),1)]);
       endif
     endif
   endif




(file #39956)
    _______________________________________________________

Additional Item Attachment:

File name: datetickV2.diff                Size:1 KB


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?50493>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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