Skip to content

Commit

Permalink
fix for DateDiff step to handle correclty child traversal (apache#2337)
Browse files Browse the repository at this point in the history
  • Loading branch information
vkagamlyk authored Nov 14, 2023
1 parent 5af507f commit 0146ebd
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 58 deletions.
2 changes: 1 addition & 1 deletion docs/src/reference/the-traversal.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ If the incoming traverser is not a Date, then an `IllegalArgumentException` will
[gremlin-groovy,modern]
----
g.inject("2023-08-02T00:00:00Z").asDate().dateDiff(inject("2023-08-03T00:00:00Z").asDate()) <1>
g.inject("2023-08-02T00:00:00Z").asDate().dateDiff(constant("2023-08-03T00:00:00Z").asDate()) <1>
----
<1> Find difference between two dates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent;
import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalUtil;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;

import java.util.Collections;
Expand Down Expand Up @@ -57,7 +58,7 @@ protected Long map(final Traverser.Admin<S> traverser) {
String.format("DateDiff can only take Date as argument, encountered %s", object.getClass()));

final Date otherDate = value != null ? value :
dateTraversal != null && dateTraversal.hasNext() ? dateTraversal.next() : null;
dateTraversal != null ? TraversalUtil.apply(traverser, dateTraversal) : null;

// let's not throw exception and assume null date == 0
final long otherDateMs = otherDate == null ? 0 : otherDate.getTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ public void shouldHandleTraversalParam() {
cal.add(Calendar.DAY_OF_MONTH, 7);
final Date other = cal.getTime();

assertEquals(-604800L, (long) __.__(now).dateDiff(__.__(other)).next());
assertEquals(-604800L, (long) __.__(now).dateDiff(__.constant(other)).next());
}

@Test
public void shouldHandleNullTraversalParam() {
final Date now = new Date();

assertEquals(now.getTime() / 1000, (long) __.__(now).dateDiff(__.__()).next());
assertEquals(now.getTime() / 1000, (long) __.__(now).dateDiff(__.constant(null)).next());
}

@Test
Expand Down
27 changes: 14 additions & 13 deletions gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs

Large diffs are not rendered by default.

27 changes: 14 additions & 13 deletions gremlin-go/driver/cucumber/gremlin.go

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0146ebd

Please sign in to comment.