# HG changeset patch # User David Bateman # Date 1337553644 -7200 # Node ID 4f458e882516324b1cd724ffd5ace8110ec71871 # Parent 161d06a52360e24585a685a9c1780623188e0fa9 Allow fractional months to datenum and correct a couple of typos in datetick (bug #36482) diff --git a/scripts/time/datenum.m b/scripts/time/datenum.m --- a/scripts/time/datenum.m +++ b/scripts/time/datenum.m @@ -85,6 +85,7 @@ ## Days until start of month assuming year starts March 1. persistent monthstart = [306; 337; 0; 31; 61; 92; 122; 153; 184; 214; 245; 275]; + persistent monthlength = [31; 28; 31; 30; 31; 30; 31; 31; 30; 31; 30; 31]; if (nargin == 0 || nargin > 6 || (nargin > 2 && (ischar (year) || iscellstr (year)))) @@ -110,6 +111,19 @@ month(month<1) = 1; ## For compatibility. Otherwise allow negative months. + ## Treat fractional months, by converting the fraction to days + if (floor (month) != month) + fracmonth = month - floor (month); + month = floor (month); + if ((mod (month-1,12) + 1) == 2 && + (floor (year/4) - floor (year/100) + floor (year/400)) != 0) + ## leap year + day += fracmonth * 29; + else + day += fracmonth * monthlength ((mod (month-1,12) + 1)); + endif + endif + ## Set start of year to March by moving Jan. and Feb. to previous year. ## Correct for months > 12 by moving to subsequent years. year += fix ((month-14)/12); diff --git a/scripts/time/datetick.m b/scripts/time/datetick.m --- a/scripts/time/datetick.m +++ b/scripts/time/datetick.m @@ -159,7 +159,7 @@ ## Day scale or less if (xmax - xmin < N / 24 / 60 / 60) scl = 1 / 24 / 60 / 60; - elseif (xmax - xmin < N / 24 / 6) + elseif (xmax - xmin < N / 24 / 60) scl = 1 / 24 / 60; else scl = 1 / 24; @@ -186,7 +186,7 @@ elseif (maxyear - minyear < N) sep = __calc_tick_sep__ (minmonth , maxmonth); xmin = datenum (ymin, sep * floor (minmonth / sep), 1); - xmax = datenum (ymin, sep * ceil (maxmonth / sep), 1); + xmax = datenum (ymax, sep * ceil (maxmonth / sep), 1); nticks = ceil (maxmonth / sep) - floor (minmonth / sep) + 1; else sep = __calc_tick_sep__ (minyear , maxyear);