Skip to content

Commit

Permalink
1. Implement custom display with ellipsis abbreviation support.
Browse files Browse the repository at this point in the history
2. floor result to prevent rounding when converting Date32 to MATLAB
datetime.

Co-authored-by: Sarah Gilmore <[email protected]>
  • Loading branch information
kevingurney and sgilmore10 committed Aug 25, 2023
1 parent 10becf4 commit aee2b4c
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion matlab/src/matlab/+arrow/+array/Date32Array.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,45 @@
validElements = arrow.internal.validate.parseValidElements(data, opts);
% UNIX Epoch (January 1st, 1970)
unixEpoch = datetime(0, ConvertFrom="posixtime");
numDays = int32(days(data - unixEpoch));
numDays = int32(floor(days(data - unixEpoch)));
args = struct(MatlabArray=numDays, Valid=validElements);
proxy = arrow.internal.proxy.create("arrow.array.proxy.Date32Array", args);
array = Date32Array(proxy);
end
end

methods (Access=protected)

function displayScalarObject(obj)
maxLength = 20;
openBracket = "[";
closeBracket = "]";
indent = " ";
data = obj.toMATLAB();
data.Format = "yyyy-MM-dd";
% Abbreviate with ellipsis if more than maxLength elements.
if obj.Length > maxLength
firstTenElements = data(1:10);
lastTenElements = data(end-9:end);
ellipsis = "...";
beforeEllipsis = indent + strjoin(string(firstTenElements), "," + newline + indent) + ",";
afterEllipsis = indent + strjoin(string(lastTenElements), "," + newline + indent);
str = ...
openBracket + newline + ...
beforeEllipsis + newline + ...
indent + ellipsis + newline + ...
afterEllipsis + newline + ...
closeBracket;
disp(str);

else
str = openBracket + newline + ...
indent + strjoin(string(data), "," + newline + indent) + newline + ...
closeBracket;
disp(str);
end
end

end

end

0 comments on commit aee2b4c

Please sign in to comment.