From 2c04adaeca4b6e6901f9316079e924156667c627 Mon Sep 17 00:00:00 2001 From: Error Prone Team Date: Thu, 19 Sep 2024 14:03:29 -0700 Subject: [PATCH] Support toSeconds in DurationToLongTimeUnit PiperOrigin-RevId: 676555168 --- .../errorprone/bugpatterns/time/DurationToLongTimeUnit.java | 1 + .../bugpatterns/time/DurationToLongTimeUnitTest.java | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/time/DurationToLongTimeUnit.java b/core/src/main/java/com/google/errorprone/bugpatterns/time/DurationToLongTimeUnit.java index 607b17714e6..6950b273498 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/time/DurationToLongTimeUnit.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/time/DurationToLongTimeUnit.java @@ -78,6 +78,7 @@ public final class DurationToLongTimeUnit extends BugChecker // JavaTime .put(instanceMethod().onExactClass(JAVA_DURATION).named("toNanos"), NANOSECONDS) .put(instanceMethod().onExactClass(JAVA_DURATION).named("toMillis"), MILLISECONDS) + .put(instanceMethod().onExactClass(JAVA_DURATION).named("toSeconds"), SECONDS) .put(instanceMethod().onExactClass(JAVA_DURATION).named("getSeconds"), SECONDS) .put(instanceMethod().onExactClass(JAVA_DURATION).named("toMinutes"), MINUTES) .put(instanceMethod().onExactClass(JAVA_DURATION).named("toHours"), HOURS) diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/time/DurationToLongTimeUnitTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/time/DurationToLongTimeUnitTest.java index fea1ade9bbd..bd85036e6ec 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/time/DurationToLongTimeUnitTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/time/DurationToLongTimeUnitTest.java @@ -43,6 +43,7 @@ void javaTime(Future f, java.time.Duration d) throws Exception { f.get(42L, TimeUnit.SECONDS); f.get(d.toNanos(), TimeUnit.NANOSECONDS); f.get(d.toMillis(), TimeUnit.MILLISECONDS); + f.get(d.toSeconds(), TimeUnit.SECONDS); f.get(d.getSeconds(), TimeUnit.SECONDS); f.get(d.toMinutes(), TimeUnit.MINUTES); f.get(d.toHours(), TimeUnit.HOURS); @@ -104,6 +105,7 @@ void javaTime(Future f, java.time.Duration d) throws Exception { f.get(42L, SECONDS); f.get(d.toNanos(), NANOSECONDS); f.get(d.toMillis(), MILLISECONDS); + f.get(d.toSeconds(), SECONDS); f.get(d.getSeconds(), SECONDS); f.get(d.toMinutes(), MINUTES); f.get(d.toHours(), HOURS); @@ -161,6 +163,8 @@ void javaTime(Future f, java.time.Duration d) throws Exception { f.get(d.toNanos(), TimeUnit.MILLISECONDS); // BUG: Diagnostic contains: f.get(d.toMillis(), TimeUnit.MILLISECONDS) f.get(d.toMillis(), TimeUnit.NANOSECONDS); + // BUG: Diagnostic contains: f.get(d.toSeconds(), TimeUnit.SECONDS) + f.get(d.toSeconds(), TimeUnit.MINUTES); // BUG: Diagnostic contains: f.get(d.getSeconds(), TimeUnit.SECONDS) f.get(d.getSeconds(), TimeUnit.MINUTES); // BUG: Diagnostic contains: f.get(d.toMinutes(), TimeUnit.MINUTES) @@ -233,6 +237,8 @@ void javaTime(Future f, java.time.Duration d) throws Exception { f.get(d.toNanos(), MILLISECONDS); // BUG: Diagnostic contains: f.get(d.toMillis(), TimeUnit.MILLISECONDS) f.get(d.toMillis(), NANOSECONDS); + // BUG: Diagnostic contains: f.get(d.toSeconds(), TimeUnit.SECONDS) + f.get(d.toSeconds(), MINUTES); // BUG: Diagnostic contains: f.get(d.getSeconds(), TimeUnit.SECONDS) f.get(d.getSeconds(), MINUTES); // BUG: Diagnostic contains: f.get(d.toMinutes(), TimeUnit.MINUTES)