Categories &

Functions List

Class Definition: calendarDuration

datatypes: calendarDuration

Array representing durations of time using flexible-length calendar date/time units.

Each calendarDuration element stores internally the number of whole months, the number of whole days, and a duration object representing hours, minutes, and seconds. It can be used to simplify calculations on datetime arrays involving calendar units.

calendarDuration arrays can be created through their constructor by combining numeric arrays representing individual calendar duration units or through the functions caldays, calweeks, calmonths, calquarters, and calyears, which create calendar durations in terms of a single calendar duration unit. These functions are also available as methods of calendarDuration arrays to extract individual calendar duration units as numeric arrays.

See also: datetime, duration

Source Code: calendarDuration

Properties

Display format, specified as a character vector or string scalar. If specified as a string scalar, it is converted and stored internally as a character vector.

Methods

calendarDuration: calD = calendarDuration (X)
calendarDuration: calD = calendarDuration (Y, MO, D)
calendarDuration: calD = calendarDuration (Y, MO, D, H, MI, S)
calendarDuration: calD = calendarDuration (Y, MO, D, T)
calendarDuration: calD = calendarDuration (…, 'Format', FMT)

calD = calendarDuration (X) returns an array of calendar durations from numeric matrix X, which must have either three or six columns, representing years, months, days, hours, minutes, and seconds, accordingly. All but seconds must be represented as whole duration units by integer values.

calD = calendarDuration (Y, MO, D) returns an array of calendar durations from numeric arrays Y, MO, and D, which correspond to years, months, and days, respectively. The size of calD is the common size of the numeric input arguments, which must be of the same size or scalars. A scalar input functions as a constant array of the same size as the other inputs.

calD = calendarDuration (Y, MO, D, H, MI, S) returns an array of calendar durations from numeric arrays Y, MO, D, H, MI, and S, which correspond to years, months, days, hours, minutes, and seconds, respectively. The size of calD is the common size of the numeric input arguments, which must be of the same size or scalars. A scalar input functions as a constant array of the same size as the other inputs.

calD = calendarDuration (Y, MO, D, T) returns an array of calendar durations from numeric arrays Y, MO, and D, which correspond to years, months, and days, as well as a time duration array T. The size of calD is the common size of the data input arguments, which must be of the same size or scalars. A scalar input functions as a constant array of the same size as the other inputs.

Numeric input arrays Y, MO, D, H, and MI must contain integer values corresponding to whole calendar units. S can also be contain fractions of seconds.

calD = calendarDuration (…, 'Format', FMT) specifies the format in which calD is displayed. FMT must be a character vector containing the following letters.

  • 'y' years
  • 'q' quarters of a year
  • 'm' months
  • 'w' weeks
  • 'd' days
  • 't' time duration

calD = calendarDuration () returns a scalar array of calendar durations with a value of zero days. To create an empty calendarDuration array, use calendarDuration ([], [], []).

See also: calyears, calquarters, calmonths, calweeks, caldays, calendarDuration, iscalendarduration, datetime, duration

calendarDuration: cstr = dispstrings (calD)

cstr = dispstrings (calD) returns a cellstr array of character vectors, cstr, which has the same size as the input calendarDuration array, calD.

calendarDuration: cstr = cellstr (calD)
calendarDuration: cstr = cellstr (calD, Format)

cstr = cellstr (calD) returns a cellstr array of character vectors, cstr, which has the same size as the input calD. cstr contains the string representations of the calendar durations in calD.

calendarDuration: cmat = char (calD)

cmat = char (calD) returns a character matrix with one row per element in calD.

calendarDuration: DV = datevec (calD)

DV = datevec (calD) returns a numeric matrix with one row per element in calD.

calendarDuration: T = time (calD)

T = time (calD) returns a duration array T with the time portions of the calendarDuration array calD.

calendarDuration: […] = split (calD, 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.

  1. 'years'
  2. 'quarters'
  3. 'months'
  4. 'weeks'
  5. 'days'
  6. 'time'

When a single date/time unit is specified, units may also be a character vector. When 'time' is specified in units, the corresponding returning 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.

calendarDuration: X = caldays (calD)

X = caldays (calD) returns a numeric array with the number of days as represented in calD.

caldays is also available as a function, in which case it performs the opposite conversion.

See also: calendarDuration.calyears, calendarDuration.calquarters, calendarDuration.calmonths, calendarDuration.calweeks, caldays

calendarDuration: X = calweeks (calD)

X = calweeks (calD) returns a numeric array with the number of weeks as represented in calD.

calweeks is also available as a function, in which case it performs the opposite conversion.

See also: calendarDuration.calyears, calendarDuration.calquarters, calendarDuration.calmonths, calendarDuration.caldays, calweeks

calendarDuration: X = calmonths (calD)

X = calmonths (calD) returns a numeric array with the number of months as represented in calD.

calmonths is also available as a function, in which case it performs the opposite conversion.

See also: calendarDuration.calyears, calendarDuration.calquarters, calendarDuration.calweeks, calendarDuration.caldays, calmonths

calendarDuration: X = calquarters (calD)

X = calmonths (calD) returns a numeric array with the number of quarters as represented in calD.

calmonths is also available as a function, in which case it performs the opposite conversion.

See also: calendarDuration.calyears, calendarDuration.calmonths, calendarDuration.calweeks, calendarDuration.caldays, calquarters

calendarDuration: X = calyears (calD)

X = calmonths (calD) returns a numeric array with the number of years as represented in calD.

calmonths is also available as a function, in which case it performs the opposite conversion.

See also: calendarDuration.calquarters, calendarDuration.calmonths, calendarDuration.calweeks, calendarDuration.caldays, calyears

calendarDuration: sz = size (calD)
calendarDuration: dim_sz = size (calD, dim)
calendarDuration: dim_sz = size (calD, d1, d2, …)
calendarDuration: [rows, columns, …, dim_n_sz] = size (…)

sz = size (calD) returns a row vector with the size (number of elements) of each dimension for the calendar duration array calD.

dim_sz = size (calD, dim) returns the size of the corresponding dimension specified in dim. If dim is a vector, then dim_sz is a vector of the same length and with each element corresponding to a specified dimension. Multiple dimensions may also be specified as separate arguments.

With a single output argument, size returns a row vector. When called with multiple output arguments, size returns the size of dimension N in the Nth argument.

calendarDuration: out = ndims (calD)

out = ndims (calD) returns the number of dimensions of the calendar duration array calD.

calendarDuration: out = numel (calD)

For compatibility reasons with Octave’s OOP interface and subsasgn behavior, calendarDuration’s numel is defined to always return 1.

calendarDuration: out = nnz (calD)

out = nnz (calD) returns the number of nonzero elements in the calendar duration array calD.

calendarDuration: N = length (calD)

N = length (calD) returns the size of the longest dimension of the calendarDuration array calD, unless any of its dimensions has zero length, in which case length (calD) returns 0.

calendarDuration: hey = keyHash (calD)

h = keyHash (calD) generates a uint64 scalar that represents the input array calD. keyHash utilizes the 64-bit FMV-1a variant of the Fowler-Noll-Vo non-cryptographic hash function.

h = keyHash (calD), base also generates a 64-bit hash code using base as the offset basis for the FNV-1a hash algorithm. base must be a uint64 integer type scalar. Use this syntax to cascade keyHash on multiple objects for which a single hash code is required.

Note that unlike MATLAB, this implementation does no use any random seed. As a result, keyHash will always generate the exact same hash key for any particular input across different workers and Octave sessions.

calendarDuration: TF = iscolumn (calD)

TF = iscolumn (calD) returns a logical scalar TF, which is true if the calendar duration array calD is a column vector and false otherwise. A column vector is a 2-D array for which size (X) returns [N, 1] with non-negative N.

calendarDuration: TF = isempty (calD)

TF = isempty (calD) returns a logical scalar TF, which is true if the calendar duration array calD is empty and false otherwise.

calendarDuration: TF = isequal (calD1, calD2)
calendarDuration: TF = isequal (calD1, calD2, …)

TF = isequal (calD1, calD2) returns a logical scalar TF, which is true if the calendar duration arrays calD1 and calD2 contain the same values and false otherwise.

TF = isequal (calD1, calD2, …) returns a logical scalar TF, which is true if all input arguments are calendar duration arrays with equal values in each corresponding elements and false otherwise.

calendarDuration: TF = isequaln (calD1, calD2)
calendarDuration: TF = isequaln (calD1, calD2, …)

TF = isequaln (calD1, calD2) returns a logical scalar TF, which is true if the calendar duration arrays calD1 and calD2 contain the same values or corresponding missing elements and false otherwise.

TF = isequaln (calD1, calD2, …) returns a logical scalar TF, which is true if all input arguments are calendar duration arrays with equal values or corresponding missing elements and false otherwise.

calendarDuration: TF = isfinite (calD)

TF = isfinite (calD) returns a logical array TF of the same size as calD containing true for each corresponding element of calD that is finite and false otherwise. Finite elements are those which are neither infinite nor Not-A-Number.

calendarDuration: TF = isinf (calD)

TF = isinf (calD) returns a logical array TF of the same size as calD containing true for each corresponding element of calD that is either Inf or -Inf and false otherwise.

calendarDuration: TF = ismatrix (calD)

TF = ismatrix (calD) returns a logical scalar TF, which is true if the calendarDuration array calD is a matrix and false otherwise. A matrix is an array of any type where ndims (X) == 2 and for which size (X) returns [H, W] with non-negative H and W.

calendarDuration: TF = ismissing (calD)

Missing values in calendarDuration arrays are represented by NaN, thus TF = ismissing (calD) is equivalent to TF = isnan (calD).

Note: ismissing for calendarDuration arrays does not support a second Indicator argument.

calendarDuration: TF = isnan (calD)

TF = isnan (calD) returns a logical array TF of the same size as calD containing true for each corresponding element of calD that is NaN and false otherwise.

calendarDuration: TF = isrow (calD)

TF = isrow (calD) returns a logical scalar TF, which is true if the calendarDuration array calD is a row vector and false otherwise. A row vector is a 2-D array for which size (X) returns [1, N] with non-negative N.

calendarDuration: TF = isscalar (calD)

TF = isscalar (calD) returns a logical scalar TF, which is true if the calendarDuration array calD is also a scalar and false otherwise. A scalar is a single element object for which size (X) returns [1, 1].

calendarDuration: TF = isvector (calD)

TF = isvector (calD) returns a logical scalar TF, which is true if the calendarDuration array calD is a vector and false otherwise. A vector is a 2-D array for which one of the dimensions is equal to 1 (either 1×N or N×1). By definition, a scalar is also a vector.

calendarDuration: C = minus (A, B)

C = minus (A, B) is the equivalent of the syntax C = A - B and returns the result of substracting the corresponding elements of B from those of A. C is a calendarDuration array of the same size as the input arguments after the necessary (if required) expansion. A and B must be size compatible, which translates to they can be the same size, one can be scalar, or for every dimension, their dimension sizes must be equal or one of them must be 1.

calendarDuration: C = minus (A)

C = uminus (A) is the equivalent of the syntax C = -A and returns A after negating its elements. C is a calendarDuration array of the same size as A.

calendarDuration: C = plus (A, B)

C = plus (A, B) is the equivalent of the syntax C = A + B and returns the result of adding the corresponding elements of A and A. C is a calendarDuration array of the same size as the input arguments after the necessary (if required) expansion. A and B must be size compatible, which translates to they can be the same size, one can be scalar, or for every dimension, their dimension sizes must be equal or one of them must be 1.

calendarDuration: C = uplus (A)

C = uminus (A) is the equivalent of the syntax C = +A and returns a copy of A. C is a calendarDuration array of the same size as A.

calendarDuration: C = cat (dim, A, B, …)

C = cat (dim, A, B, …) concatenates calendarDuration arrays A, B, … along dimension dim. All input arrays must have the same size except along the operating dimension dim. Any of the input arrays may also be string arrays or cell arrays of character vectors of compatible size. Additionally, an input can be a numeric matrix, which when parsed to the constructor will return a calendarDuration array of compatible size.

calendarDuration: C = horzcat (A, B, …)

C = horzcat (A, B, … is the equivalent of the syntax B = [A, B, …] and horizontally concatenates the calendarDuration arrays A, B, …. All input arrays must have the same size except along the second dimension. Any of the input arrays may also be string arrays or cell arrays of character vectors of compatible size. Additionally, an input can be a numeric matrix, which when parsed to the constructor will return a calendarDuration array of compatible size.

calendarDuration: C = vertat (A, B, …)

C = vertat (A, B, … is the equivalent of the syntax B = [A; B; …] and vertically concatenates the calendarDuration arrays A, B, …. All input arrays must have the same size except along the first dimension. Any of the input arrays may also be string arrays or cell arrays of character vectors of compatible size. Additionally, an input can be a numeric matrix, which when parsed to the constructor will return a calendarDuration array of compatible size.

calendarDuration: B = repmat (A, n)
calendarDuration: B = repmat (A, d1, …, dN)
calendarDuration: B = repmat (A, dimvec)

B = repmat (A, n) returns a calendarDuration array B containing n copies of the input calendarDuration array A along every dimension of A.

B = repmat (A, d1, …, dN) returns an array B containing copies of A along the dimensions specified by the list of scalar integer values d1, …, dN, which specify how many copies of A are made in each dimension.

B = repmat (A, dimvec) is equivalent to the previous syntax with dimvec = [d1, …, dN].

calendarDuration: B = repelem (A, n)
calendarDuration: B = repelem (A, d1, …, dN)

B = repelem (A, n) returns a calendarDuration vector B containing repeated elements of the input A, which must be a calendarDuration vector. If n is a scalar, each element of A is repeated n times along the non-singleton dimension of A. If n is a vector, it must have the same elemnts as A, in which case it specifies the number of times to repeat each corresponding element of A.

B = repelem (A, d1, …, dN returns an array B with each element of A repeated according to the the list of input arguments d1, …, dN each corresponding to a different dimension 1:ndims (A) of the input array A. d1, …, dN must be either scalars or vectors with the same length as the corresponding dimension of A containing non-negative integer values specifying the number of repetitions of each element along the corresponding dimension.

calendarDuration: B = repelems (A, R)

B = repelems (A, R) returns a calendarDuration vector B containing repeated elements of the input A, which must be a calendarDuration vector. R must be a 2×N matrix of integers. Entries in the first row of R correspond to the linear indexing of the elements in A to be repeated. The corresponding entries in the second row of R specify the repeat count of each element.

calendarDuration: B = reshape (A, d1, …, dN)
calendarDuration: B = reshape (A, …, [], …)
calendarDuration: B = reshape (A, dimvec)

B = reshape (A, d1, …, dN) returns a calendarDuration array B with specified dimensions d1, …, dN, whose elements are taken columnwise from the calendarDuration array A. The product of d1, …, dN must equal the total number of elements in A.

B = reshape (A, …, [], …) returns a calendarDuration array B with one dimension unspecified which is calculated automatically so that the product of dimensions in B matches the total elements in A, which must be divisible the product of specified dimensions. An empty matrix ([]) is used to flag the unspecified dimension.

calendarDuration: B = circshift (A, n)
calendarDuration: B = circshift (A, n, dim)

B = circshift (A, n) circularly shifts the elements of the calendarDuration array A according to n. If n is a nonzero integer scalar, then the elements of A are shifted by n elements along the first non-singleton dimension of A. If n is a vector, it must not be longer that the number of dimensions of A with each value of n corresponding to a dimension in A. The sign of the value(s) in n specify the direction in the elements of A are shifted.

B = circshift (A, n, dim) circularly shifts the elements of the calendarDuration array A along the dimension specified by dim. In this case, n must be a scalar integer value.

calendarDuration: B = permute (A, dims)

B = permute (A, dims) returns the generalized transpose of the calendarDuration array A by rearranging its dimensions according to the permutation vector specified in dims.

dims must index all the dimensions 1:ndims (A) of the input array A, in any order, but only once. The Nth dimension of A gets remapped to the dimension in B specified by dims(N).

calendarDuration: A = ipermute (B, dims)

A = ipermute (B, dims) returns the inverse of the generalized transpose performed by the permute function. The expression ipermute (permute (A, dims), dims) returns the original array A.

dims must index all the dimensions 1:ndims (B) of the input array B, in any order, but only once. The dimension of B specified in dims(N) gets remapped to the Nth dimension of A.

calendarDuration: B = transpose (A)

B = transpose (A) is the equivalent of the syntax B = A.' and returns the transpose of the calendarDuration matrix A.

calendarDuration: B = ctranspose (A)

B = ctranspose (A) is the equivalent of the syntax B = A' and returns the transpose of the calendarDuration matrix A. For calendarDuration arrays, ctranspose is identical to transpose.