This is an automated email from the ASF dual-hosted git repository.

kevingurney pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new 3262debb10 GH-37252: [MATLAB] Add `arrow.type.DateUnit` enumeration 
class (#37280)
3262debb10 is described below

commit 3262debb107599a39c39c78b461029ee5910669b
Author: Kevin Gurney <[email protected]>
AuthorDate: Mon Aug 21 13:49:33 2023 -0400

    GH-37252: [MATLAB] Add `arrow.type.DateUnit` enumeration class (#37280)
    
    ### Rationale for this change
    
    In support of adding  `arrow.type.Date32Type` and `arrow.type.Date64Type`, 
this pull request adds a `arrow.type.DateUnit` enumeration class mirroring the 
`arrow.type.TimeUnit` enumeration class.
    
    `arrow.type.DateUnit` will have two values: `Day` and `Millisecond`.
    
    ### What changes are included in this PR?
    
    1. Added a new enumeration class `arrow.type.DateUnit` which mirrors the 
`arrow.type.TimeUnit` enumeration class.
    
    **Example**:
    
    ```matlab
    >> day = arrow.type.DateUnit.Day
    
    day =
    
      DateUnit enumeration
    
        Day
    
    >> millisecond = arrow.type.DateUnit.Millisecond
    
    millisecond =
    
      DateUnit enumeration
    
        Millisecond
    ```
    
    ### Are these changes tested?
    
    Yes.
    
    1. Added a new test class `tDateUnit` for `arrow.type.DateUnit` tests.
    2. Updated code for `tTimeUnit` for consistency with `tDateUnit`.
    
    ### Are there any user-facing changes?
    
    Yes.
    
    1. There is now a new user-facing `arrow.type.DateUnit` enumeration class.
    
    ### Future Directions
    
    1. Add an `arrow.internal.validate.temporal.dateUnit` helper function that 
mirrors `arrow.internal.validate.temporal.timeUnit`.
    2. #37229
    3. #37230
    * Closes: #37252
    
    Lead-authored-by: Kevin Gurney <[email protected]>
    Co-authored-by: Sarah Gilmore <[email protected]>
    Signed-off-by: Kevin Gurney <[email protected]>
---
 .../matlab/+arrow/+type/{TimeUnit.m => DateUnit.m} | 26 +++----------
 matlab/src/matlab/+arrow/+type/TimeUnit.m          |  5 ++-
 .../TimeUnit.m => test/arrow/type/tDateUnit.m}     | 44 ++++++++++-----------
 matlab/test/arrow/type/tTimeUnit.m                 | 45 ++++++++++++++--------
 4 files changed, 58 insertions(+), 62 deletions(-)

diff --git a/matlab/src/matlab/+arrow/+type/TimeUnit.m 
b/matlab/src/matlab/+arrow/+type/DateUnit.m
similarity index 57%
copy from matlab/src/matlab/+arrow/+type/TimeUnit.m
copy to matlab/src/matlab/+arrow/+type/DateUnit.m
index 358818be98..bb82de5b02 100644
--- a/matlab/src/matlab/+arrow/+type/TimeUnit.m
+++ b/matlab/src/matlab/+arrow/+type/DateUnit.m
@@ -1,3 +1,5 @@
+% Enumeration class representing Date Units.
+
 % Licensed to the Apache Software Foundation (ASF) under one or more
 % contributor license agreements.  See the NOTICE file distributed with
 % this work for additional information regarding copyright ownership.
@@ -12,29 +14,11 @@
 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 % implied.  See the License for the specific language governing
 % permissions and limitations under the License.
-classdef TimeUnit < int16
-% Enumeration class representing Time Units.
+classdef DateUnit < uint8
 
     enumeration
-        Second       (0)
+        Day          (0)
         Millisecond  (1)
-        Microsecond  (2)
-        Nanosecond   (3)
     end
 
-    methods (Hidden)
-        function ticks = ticksPerSecond(obj)
-            import arrow.type.TimeUnit
-            switch obj
-                case TimeUnit.Second
-                    ticks = 1;
-                case TimeUnit.Millisecond
-                    ticks = 1e3;
-                case TimeUnit.Microsecond
-                    ticks = 1e6;
-                case TimeUnit.Nanosecond
-                    ticks = 1e9;
-            end
-        end
-    end
-end
\ No newline at end of file
+end
diff --git a/matlab/src/matlab/+arrow/+type/TimeUnit.m 
b/matlab/src/matlab/+arrow/+type/TimeUnit.m
index 358818be98..802ff124c2 100644
--- a/matlab/src/matlab/+arrow/+type/TimeUnit.m
+++ b/matlab/src/matlab/+arrow/+type/TimeUnit.m
@@ -1,3 +1,5 @@
+% Enumeration class representing Time Units.
+
 % Licensed to the Apache Software Foundation (ASF) under one or more
 % contributor license agreements.  See the NOTICE file distributed with
 % this work for additional information regarding copyright ownership.
@@ -12,8 +14,7 @@
 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 % implied.  See the License for the specific language governing
 % permissions and limitations under the License.
-classdef TimeUnit < int16
-% Enumeration class representing Time Units.
+classdef TimeUnit < uint8
 
     enumeration
         Second       (0)
diff --git a/matlab/src/matlab/+arrow/+type/TimeUnit.m 
b/matlab/test/arrow/type/tDateUnit.m
similarity index 56%
copy from matlab/src/matlab/+arrow/+type/TimeUnit.m
copy to matlab/test/arrow/type/tDateUnit.m
index 358818be98..b0108bf4b3 100644
--- a/matlab/src/matlab/+arrow/+type/TimeUnit.m
+++ b/matlab/test/arrow/type/tDateUnit.m
@@ -1,3 +1,5 @@
+% Tests for the arrow.type.DateUnit enumeration class
+
 % Licensed to the Apache Software Foundation (ASF) under one or more
 % contributor license agreements.  See the NOTICE file distributed with
 % this work for additional information regarding copyright ownership.
@@ -12,29 +14,27 @@
 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 % implied.  See the License for the specific language governing
 % permissions and limitations under the License.
-classdef TimeUnit < int16
-% Enumeration class representing Time Units.
-
-    enumeration
-        Second       (0)
-        Millisecond  (1)
-        Microsecond  (2)
-        Nanosecond   (3)
+classdef tDateUnit < matlab.unittest.TestCase
+
+    properties (Constant)
+        ClassName = "arrow.type.DateUnit";
+        EnumerationValues = [ ...
+            arrow.type.DateUnit.Day; ...
+            arrow.type.DateUnit.Millisecond ...
+        ];
     end
+    
+    methods (Test)
+
+        function SupportedValues(testCase)
+            % Verify there are two supported DateUnit enumeration values.
+
+            actualEnumerationValues = enumeration(testCase.ClassName);
 
-    methods (Hidden)
-        function ticks = ticksPerSecond(obj)
-            import arrow.type.TimeUnit
-            switch obj
-                case TimeUnit.Second
-                    ticks = 1;
-                case TimeUnit.Millisecond
-                    ticks = 1e3;
-                case TimeUnit.Microsecond
-                    ticks = 1e6;
-                case TimeUnit.Nanosecond
-                    ticks = 1e9;
-            end
+            testCase.verifyEqual(actualEnumerationValues, 
testCase.EnumerationValues);
         end
+
     end
-end
\ No newline at end of file
+
+end
+
diff --git a/matlab/test/arrow/type/tTimeUnit.m 
b/matlab/test/arrow/type/tTimeUnit.m
index 0c2432193a..4a1a866b23 100644
--- a/matlab/test/arrow/type/tTimeUnit.m
+++ b/matlab/test/arrow/type/tTimeUnit.m
@@ -1,3 +1,5 @@
+% Tests for the arrow.type.TimeUnit enumeration class
+
 % Licensed to the Apache Software Foundation (ASF) under one or more
 % contributor license agreements.  See the NOTICE file distributed with
 % this work for additional information regarding copyright ownership.
@@ -13,29 +15,38 @@
 % implied.  See the License for the specific language governing
 % permissions and limitations under the License.
 classdef tTimeUnit < matlab.unittest.TestCase
-% Test class for arrow.type.timeUnit
+
+    properties (Constant)
+        ClassName = "arrow.type.TimeUnit";
+        EnumerationValues = [ ...
+            arrow.type.TimeUnit.Second; ...
+            arrow.type.TimeUnit.Millisecond; ...
+            arrow.type.TimeUnit.Microsecond; ...
+            arrow.type.TimeUnit.Nanosecond ...
+        ];
+    end
     
     methods (Test)
-        function Values(testCase)
-        % Verify there are four TimeUnit enum values.
-            import arrow.type.TimeUnit
-            values = enumeration(TimeUnit.Second);
-            expectedValues = [TimeUnit.Second, TimeUnit.Millisecond, ...
-                              TimeUnit.Microsecond, TimeUnit.Nanosecond]';
-            testCase.verifyEqual(values, expectedValues);
+
+        function SupportedValues(testCase)
+            % Verify there are four supported TimeUnit enumeration values.
+
+            actualEnumerationValues = enumeration(testCase.ClassName);
+
+            testCase.verifyEqual(actualEnumerationValues, 
testCase.EnumerationValues);
         end
 
         function TicksPerSecond(testCase)
-        % Verify the TicksPerSecond property has the right value for each
-        % TimeUnit value.
-            import arrow.type.TimeUnit
-            units = [TimeUnit.Second, TimeUnit.Millisecond, ...
-                              TimeUnit.Microsecond, TimeUnit.Nanosecond]';
-            ticks = [1 1e3 1e6 1e9];
-            for ii = 1:numel(units)
-                testCase.verifyEqual(ticksPerSecond(units(ii)), ticks(ii));
+            % Verify the TicksPerSecond property has the right value for
+            % each TimeUnit enumeration value.
+
+            expectedTicksPerSecond = [1 1e3 1e6 1e9];
+            for ii = 1:numel(testCase.EnumerationValues)
+                actualTicksPerSecond = 
ticksPerSecond(testCase.EnumerationValues(ii));
+                testCase.verifyEqual(actualTicksPerSecond, 
expectedTicksPerSecond(ii));
             end
         end
+
     end
-end
 
+end
\ No newline at end of file

Reply via email to