duration.isregular
duration: TF = isregular (D)
duration: TF = isregular (D, COMPONENT)
duration: [TF, DT] = isregular (…)
Return true if a duration vector is regularly spaced.
TF = isregular (D) returns true when the elements of
the duration vector D are evenly spaced, that is, when every step
from one element to the next is the same and is not zero. A second
output DT gives that step, and is NaN when there is none.
A sequence that does not move is not regularly spaced: a step of zero
describes no spacing, so isregular of a constant vector is false.
A descending vector is regular, with a negative step. A NaN or an
infinite element anywhere makes the vector irregular, as does having
fewer than two elements, so a scalar and an empty array are both false.
D must be a vector; a matrix is an error.
TF = isregular (D, COMPONENT) asks about a
particular component, one of 'Years', 'Quarters',
'Months', 'Weeks', 'Days' or 'Time'. A
duration measures elapsed time and knows nothing of a calendar, so only
'Time', the default, can be true; every calendar component is
false however the vector is spaced. The argument exists so that a
duration can be asked the same question as a datetime.
Steps are compared within a few eps of the largest value present
rather than exactly, because subtracting neighbouring durations rounds:
even one, two and three hours have steps differing in the last bit, and
an exact test would call that irregular. MATLAB tolerates a difference
of about the same size, for the same reason.
Deviation from MATLAB. A negative step is returned there formatted in seconds whatever the vector’s own format; here the step keeps D’s format whichever way the vector runs.
Source Code: duration