Commits


sgilmore10 authored and GitHub committed c49e2427316
GH-38420: [MATLAB] Implement a `DatetimeValidator` class that validates a MATLAB `cell` array contains only values of zoned or unzoned `datetime`s (#38533) ### Rationale for this change This is a followup to #38419. Adding this `DatetimeTypeValidator` class is a step towards implementing the `arrow.array.ListArray.fromMATLAB()` method for creating `ListArray`s whose `ValueType`s is a timestamp array from a MATLAB `cell` array. This validator will ensure the cell array contain only `datetime`s or unzoned `datetime`s. This is a requirement when creating a `List` of `Timestamp`s because two MATLAB `datetime`s can only be concatenated together if they are either both zoned or both unzoned: ```matlab >> d1 = datetime(2023, 10, 31, TimeZone="America/New_York"); >> d2 =datetime(2023, 11, 1); >> [d1; d2] Error using datetime/vertcat Unable to concatenate a datetime array that has a time zone with one that does not have a time zone. ``` ### What changes are included in this PR? Added a new MATLAB class called `arrow.array.internal.list.DatetimeValidator`, which inherits from `arrow.array.internal.list.ClassTypeValidator`. This new class defines one property called `HasTimeZone`, which is a scalar `logical` indicating if the validator expects all `datetime`s to be zoned or not. Additionally, `DatetimeValidator` overrides the `validateElement` method. It first call's `ClassTypeValidator`'s implementation of `validateElement` to verify the input element is a `datetime`. If so, it then confirms that the input `datetime`'s TimeZone property is empty or nonempty, based on the validator's `HasTimeZone` property value. ### Are these changes tested? Yes, I added a new test class called `tDatetimeValidator.m`. ### Are there any user-facing changes? No. ### Future Directions 1. #38417 2. #38354 * Closes: #38420 Authored-by: Sarah Gilmore <sgilmore@mathworks.com> Signed-off-by: Kevin Gurney <kgurney@mathworks.com>