Skip to content

Commit

Permalink
Merge branch '3.7-dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
spmallette committed Oct 18, 2024
2 parents fbe7bd8 + 0c34840 commit 4982988
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ This release also includes changes from <<release-3-6-8, 3.6.8>>.
* Deprecated public constructor for `SeedStrategy` in favor of builder pattern to be consistent with other strategies.
* Allowed specification of a customized Spark app name.
* Added getter method to `CoinStep` for its probability field.
* Prevented decimal values from being parsed by `asDate()`.
* Prevented specification of `Cardinality` to `option()` when not used in conjunction with `mergeV()`.
* Exposed a mechanism for providers to customize the assertion of error messages in feature tests.
* Attempted to detect JDK version for Gremlin Console to avoid problems with Java 17 if `neo4j-gremlin` is used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
import org.apache.tinkerpop.gremlin.util.DatetimeHelper;

import java.math.BigInteger;
import java.time.format.DateTimeParseException;
import java.util.Collections;
import java.util.Date;
Expand All @@ -51,9 +52,17 @@ protected Date map(final Traverser.Admin<S> traverser) {
throw new IllegalArgumentException("Can't parse null as Date.");
if (object instanceof Date)
return (Date) object;
if (object instanceof Number)
if (object instanceof Byte || object instanceof Short || object instanceof Integer || object instanceof Long)
// numbers handled as milliseconds since January 1, 1970, 00:00:00 GMT.
return new Date(((Number) object).longValue());
if (object instanceof BigInteger) {
try {
return new Date(((BigInteger) object).longValueExact());
} catch (ArithmeticException ae) {
throw new IllegalArgumentException("Can't parse " + object + " as Date.");
}
}

if (object instanceof String) {
try {
return DatetimeHelper.parse((String) object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.tinkerpop.gremlin.process.traversal.step.StepTest;
import org.junit.Test;

import java.math.BigInteger;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.Arrays;
Expand All @@ -48,8 +49,8 @@ public void shouldParseDate() {
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(new Date(6), __.__(new BigInteger("6")).asDate().next());
assertEquals(testDate, __.__(testDate.getTime()).asDate().next());

assertEquals(testDate, __.__("2023-08-02T00:00:00Z").asDate().next());
Expand All @@ -71,6 +72,16 @@ public void shouldThrowExceptionWhenUUIDInput() {
__.__(UUID.randomUUID()).asDate().next();
}

@Test(expected = IllegalArgumentException.class)
public void shouldThrowExceptionWhenDecimalInput() {
__.__(2.2d).asDate().next();
}

@Test(expected = IllegalArgumentException.class)
public void shouldThrowExceptionWhenBigIntegerOutOfLongInput() {
__.__(new BigInteger("1000000000000000000000")).asDate().next();
}

@Test(expected = IllegalArgumentException.class)
public void shouldThrowExceptionWhenNullInput() {
__.__(null).asDate().next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ Feature: Step - asDate()
g.inject(xx1).asDate()
"""
When iterated to list
Then the result should be unordered
| result |
| dt[2023-09-06T16:28:29Z] |
Then the traversal will raise an error with message containing text of "Can't parse"

@GraphComputerVerificationInjectionNotSupported
Scenario: g_injectX1_2X_asDate
Expand Down

0 comments on commit 4982988

Please sign in to comment.