kmcginnes commented on code in PR #3090:
URL: https://github.com/apache/tinkerpop/pull/3090#discussion_r2029544507


##########
gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/DateDiffStepTest.java:
##########
@@ -36,64 +35,49 @@ public class DateDiffStepTest extends StepTest {
 
     @Override
     protected List<Traversal> getTraversals() {
-        return Collections.singletonList(__.dateDiff(new 
Date(1690934420000L)));
+        return 
Collections.singletonList(__.dateDiff(OffsetDateTime.parse("2023-08-02T00:00:20Z")));
     }
 
     @Test
     public void shouldHandlePositiveValues() {
-        final Date now = new Date();
-
-        final Calendar cal = Calendar.getInstance();
-        cal.setTime(now);
-        cal.setTimeZone(TimeZone.getTimeZone(UTC));
-        cal.add(Calendar.DAY_OF_MONTH, 7);
-        final Date other = cal.getTime();
+        final OffsetDateTime now = OffsetDateTime.now(UTC);
+        final OffsetDateTime other = now.plus(Duration.ofDays(7));
 
         assertEquals(604800L, (long) __.__(other).dateDiff(now).next());
     }
 
     @Test
     public void shouldHandleNegativeValues() {
-        final Date now = new Date();
-
-        final Calendar cal = Calendar.getInstance();
-        cal.setTime(now);
-        cal.setTimeZone(TimeZone.getTimeZone(UTC));
-        cal.add(Calendar.DAY_OF_MONTH, 7);
-        final Date other = cal.getTime();
+        final OffsetDateTime now = OffsetDateTime.now(UTC);
+        final OffsetDateTime other = now.plus(Duration.ofDays(7));
 
         assertEquals(-604800L, (long) __.__(now).dateDiff(other).next());
     }
 
     @Test
     public void shouldHandleTraversalParam() {
-        final Date now = new Date();
-
-        final Calendar cal = Calendar.getInstance();
-        cal.setTime(now);
-        cal.setTimeZone(TimeZone.getTimeZone(UTC));
-        cal.add(Calendar.DAY_OF_MONTH, 7);
-        final Date other = cal.getTime();
+        final OffsetDateTime now = OffsetDateTime.now(UTC);
+        final OffsetDateTime other = now.plus(Duration.ofDays(7));
 
         assertEquals(-604800L, (long) 
__.__(now).dateDiff(__.constant(other)).next());
     }
 
     @Test
     public void shouldHandleNullTraversalParam() {
-        final Date now = new Date();
+        final OffsetDateTime now = OffsetDateTime.now(UTC);
 
-        assertEquals(now.getTime() / 1000, (long) 
__.__(now).dateDiff(__.constant(null)).next());
+        assertEquals(now.toEpochSecond(), (long) 
__.__(now).dateDiff(__.constant(null)).next());

Review Comment:
   Drops precision from milliseconds to seconds.



##########
gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/DateDiffStepTest.java:
##########
@@ -36,64 +35,49 @@ public class DateDiffStepTest extends StepTest {
 
     @Override
     protected List<Traversal> getTraversals() {
-        return Collections.singletonList(__.dateDiff(new 
Date(1690934420000L)));
+        return 
Collections.singletonList(__.dateDiff(OffsetDateTime.parse("2023-08-02T00:00:20Z")));
     }
 
     @Test
     public void shouldHandlePositiveValues() {
-        final Date now = new Date();
-
-        final Calendar cal = Calendar.getInstance();
-        cal.setTime(now);
-        cal.setTimeZone(TimeZone.getTimeZone(UTC));
-        cal.add(Calendar.DAY_OF_MONTH, 7);
-        final Date other = cal.getTime();
+        final OffsetDateTime now = OffsetDateTime.now(UTC);
+        final OffsetDateTime other = now.plus(Duration.ofDays(7));
 
         assertEquals(604800L, (long) __.__(other).dateDiff(now).next());
     }
 
     @Test
     public void shouldHandleNegativeValues() {
-        final Date now = new Date();
-
-        final Calendar cal = Calendar.getInstance();
-        cal.setTime(now);
-        cal.setTimeZone(TimeZone.getTimeZone(UTC));
-        cal.add(Calendar.DAY_OF_MONTH, 7);
-        final Date other = cal.getTime();
+        final OffsetDateTime now = OffsetDateTime.now(UTC);
+        final OffsetDateTime other = now.plus(Duration.ofDays(7));
 
         assertEquals(-604800L, (long) __.__(now).dateDiff(other).next());
     }
 
     @Test
     public void shouldHandleTraversalParam() {
-        final Date now = new Date();
-
-        final Calendar cal = Calendar.getInstance();
-        cal.setTime(now);
-        cal.setTimeZone(TimeZone.getTimeZone(UTC));
-        cal.add(Calendar.DAY_OF_MONTH, 7);
-        final Date other = cal.getTime();
+        final OffsetDateTime now = OffsetDateTime.now(UTC);
+        final OffsetDateTime other = now.plus(Duration.ofDays(7));
 
         assertEquals(-604800L, (long) 
__.__(now).dateDiff(__.constant(other)).next());
     }
 
     @Test
     public void shouldHandleNullTraversalParam() {
-        final Date now = new Date();
+        final OffsetDateTime now = OffsetDateTime.now(UTC);
 
-        assertEquals(now.getTime() / 1000, (long) 
__.__(now).dateDiff(__.constant(null)).next());
+        assertEquals(now.toEpochSecond(), (long) 
__.__(now).dateDiff(__.constant(null)).next());

Review Comment:
   Drops precision from milliseconds to seconds.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to