calendarDuration.split
calendarDuration: […] = split (calD, units)
Split calendarDuration array into numeric and duration units.
[…] = split (calD, units) splits the calendar
duration units in calD into separate numeric arrays according to
date/time units specified in units, which must be either a cell
array of character vectors or a string array containing any of the
following date/time units in descending order.
'years'
'quarters'
'months'
'weeks'
'days'
'time'
When a single date/time unit is specified, units may also be a
character vector. When 'time' is specified in units, the
corresponding returned argument is a duration array. The values
of years, quarters, and months are computed independently from the values
of weeks and days in calD, with larger units taking precedence when
specified The same applies for duration arrays, when requested.
Each unit may be abbreviated to any leading part of its name and is
matched without regard to case, so 'y', 'Year' and
'YEARS' all name years. No abbreviation is ambiguous, the six
names starting with six different letters. A unit named more than once
still asks for a single component.
Fewer output arguments than units may be requested, in which case only the leading ones are returned; asking for more is an error. An element that is not finite keeps that same value in every component it is divided into, so splitting an infinite calendar duration gives infinite years, months and days alike.
Source Code: calendarDuration
split decomposes a calendar duration into the whole-unit components you request, distributing the span across them. (Contrast the single-unit extractors such as calmonths, which each return the span as a total in one unit.)
d = calendarDuration (2, 3, 40)
d = calendarDuration 2y 3mo 40d
[y, mo, days] = split (d, {'years', 'months', 'days'});
[y, mo, days]
ans =
2 3 40
Unit names may be abbreviated to any leading part and are matched without regard to case, and fewer outputs than units may be asked for — you get the leading ones.
d = calendarDuration (2, 3, 40)
d = calendarDuration 2y 3mo 40d
split (d, 'y')
ans = 2
[y, q] = split (d, {'Years', 'QUARTERS', 'months'});
[y, q]
ans = 2 1