You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by "Cole-Greer (via GitHub)" <gi...@apache.org> on 2023/09/07 01:06:09 UTC

[GitHub] [tinkerpop] Cole-Greer commented on a diff in pull request #2223: Date functions

Cole-Greer commented on code in PR #2223:
URL: https://github.com/apache/tinkerpop/pull/2223#discussion_r1317954204


##########
gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/DateAddStepTest.java:
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, 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.
+ */
+package org.apache.tinkerpop.gremlin.process.traversal.step.map;
+
+import org.apache.tinkerpop.gremlin.process.traversal.DT;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.process.traversal.step.StepTest;
+import org.junit.Test;
+
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+public class DateAddStepTest extends StepTest {
+
+    @Override
+    protected List<Traversal> getTraversals() {
+        return Collections.singletonList(__.dateAdd(DT.hour, 5));
+    }
+
+    @Test
+    public void shouldAddHours() {
+        final Date now = new Date();
+
+        final Calendar cal = Calendar.getInstance();
+        cal.setTime(now);
+        cal.add(Calendar.HOUR_OF_DAY, 2);
+        final Date expected = cal.getTime();
+
+        assertEquals(expected, __.__(now).dateAdd(DT.hour, 2).next());
+    }
+
+    @Test
+    public void shouldAddNegativeHours() {

Review Comment:
   Could you add similar tests for negative minutes, seconds, and days?



##########
gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AsDateStepTest.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, 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.
+ */
+package org.apache.tinkerpop.gremlin.process.traversal.step.map;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.process.traversal.step.StepTest;
+import org.junit.Test;
+
+import java.time.Instant;
+import java.time.ZonedDateTime;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.UUID;
+
+import static java.time.ZoneOffset.UTC;
+import static org.junit.Assert.assertEquals;
+
+public class AsDateStepTest extends StepTest {
+
+    @Override
+    protected List<Traversal> getTraversals() {
+        return Collections.singletonList(__.asDate());
+    }
+
+    @Test
+    public void shouldParseDate() {
+
+        final Instant testInstant = ZonedDateTime.of(2023, 8, 2, 0, 0, 0, 0, UTC).toInstant();
+        final Date testDate = new Date(testInstant.getEpochSecond() * 1000);
+
+        assertEquals(new Date(1), __.__(1).asDate().next());
+        assertEquals(new Date(2), __.__(2.0).asDate().next());
+        assertEquals(new Date(3), __.__(3L).asDate().next());
+        assertEquals(testDate, __.__(testDate.getTime()).asDate().next());
+
+        assertEquals(testDate, __.__("2023-08-02T00:00:00Z").asDate().next());

Review Comment:
   What is the expected behavior of `g.inject("This String is not an ISO 8601 Date").asDate()`? I assume IllegalArgumentException would make sense here. Should this be an additional test case?



##########
gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/map/DateAdd.feature:
##########
@@ -0,0 +1,79 @@
+# 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.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, 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.
+
+@StepClassMap @StepDateAdd
+Feature: Step - dateAdd()
+
+  @GraphComputerVerificationInjectionNotSupported
+  Scenario: g_injectXdatetimeXstrXX_dateAddXDT_hour_2X
+    Given the empty graph
+    And the traversal of
+      """
+      g.inject(datetime('2023-08-02T00:00:00Z')).dateAdd(DT.hour, 2)
+      """
+    When iterated to list
+    Then the result should be unordered
+      | result |
+      | dt[2023-08-02T02:00:00Z] |
+
+  @GraphComputerVerificationInjectionNotSupported
+  Scenario: g_injectXdatetimeXstrXX_dateAddXhour_2X
+    Given the empty graph
+    And the traversal of
+      """
+      g.inject(datetime('2023-08-02T00:00:00Z')).dateAdd(hour, 2)
+      """
+    When iterated to list
+    Then the result should be unordered
+      | result |
+      | dt[2023-08-02T02:00:00Z] |
+
+  @GraphComputerVerificationInjectionNotSupported
+  Scenario: g_injectXdatetimeXstrXX_dateAddXhour_1X
+    Given the empty graph
+    And the traversal of
+      """
+      g.inject(datetime('2023-08-02T00:00:00Z')).dateAdd(hour, -1)
+      """
+    When iterated to list
+    Then the result should be unordered
+      | result |
+      | dt[2023-08-01T23:00:00Z] |
+
+  @GraphComputerVerificationInjectionNotSupported
+  Scenario: g_injectXdatetimeXstrXX_dateAddXminute_10X
+    Given the empty graph
+    And the traversal of
+      """
+      g.inject(datetime('2023-08-02T00:00:00Z')).dateAdd(minute, 10)
+      """
+    When iterated to list
+    Then the result should be unordered
+      | result |
+      | dt[2023-08-02T00:10:00Z] |
+
+  @GraphComputerVerificationInjectionNotSupported

Review Comment:
   Consider adding a test for `dateAdd(day, 10)`



##########
gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/map/AsDate.feature:
##########
@@ -0,0 +1,90 @@
+# 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.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, 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.
+
+@StepClassMap @StepAsDate
+Feature: Step - asDate()
+
+  @GraphComputerVerificationInjectionNotSupported
+  Scenario: g_injectXstrX_asDate
+    Given the empty graph
+    And the traversal of
+      """
+      g.inject("2023-08-02T00:00:00Z").asDate()
+      """
+    When iterated to list
+    Then the result should be unordered
+      | result |
+      | dt[2023-08-02T00:00:00Z] |
+
+  @GraphComputerVerificationInjectionNotSupported
+  Scenario: g_injectX1694017707000X_asDate
+    Given the empty graph
+    And the traversal of
+      """
+      g.inject(1694017707000).asDate()
+      """
+    When iterated to list
+    Then the result should be unordered
+      | result |
+      | dt[2023-09-06T16:28:27Z] |
+
+  @GraphComputerVerificationInjectionNotSupported
+  Scenario: g_injectX1694017708000LX_asDate
+    Given the empty graph
+    And using the parameter xx1 defined as "d[1694017708000].l"
+    And the traversal of
+      """
+      g.inject(xx1).asDate()
+      """
+    When iterated to list
+    Then the result should be unordered
+      | result |
+      | dt[2023-09-06T16:28:28Z] |
+
+  @GraphComputerVerificationInjectionNotSupported
+  Scenario: g_injectX1694017709000dX_asDate
+    Given the empty graph
+    And using the parameter xx1 defined as "d[1694017709000.1].d"
+    And the traversal of
+      """
+      g.inject(xx1).asDate()
+      """
+    When iterated to list
+    Then the result should be unordered
+      | result |
+      | dt[2023-09-06T16:28:29Z] |
+
+  @GraphComputerVerificationInjectionNotSupported
+  Scenario: g_injectX1_2X_asDate
+    Given the empty graph
+    And using the parameter xx1 defined as "l[1,2]"
+    And the traversal of
+      """
+      g.inject(xx1).asDate()
+      """
+    When iterated to list
+    Then the traversal will raise an error with message containing text of "Can't parse"
+
+  @GraphComputerVerificationInjectionNotSupported

Review Comment:
   Similar to previous process test comment, consider adding a test for a non-ISO string input.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org