aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-09-20 10:16:36 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-09-21 09:54:23 +0200
commite4a4f742a5c70e7886fb53d76c0e3e44797b52dd (patch)
treecfe493086bd5838b4581f07e5fd31183fde2159a /sonar-plugin-api
parent312fa3ba13f096aa08aca799d13b9335eda059a7 (diff)
downloadsonarqube-e4a4f742a5c70e7886fb53d76c0e3e44797b52dd.tar.gz
sonarqube-e4a4f742a5c70e7886fb53d76c0e3e44797b52dd.zip
add DateUtils#truncateToSeconds and use it instead of +1_000L
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java18
1 files changed, 18 insertions, 0 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java
index ea232916471..01e93aafa03 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java
@@ -285,4 +285,22 @@ public final class DateUtils {
return Date.from(date.toInstant().plus(numberOfDays, ChronoUnit.DAYS));
}
+ @CheckForNull
+ public static Date truncateToSeconds(@Nullable Date d) {
+ if (d == null) {
+ return null;
+ }
+ return truncateToSecondsImpl(d);
+ }
+
+ public static long truncateToSeconds(long dateTime) {
+ return truncateToSecondsImpl(new Date(dateTime)).getTime();
+ }
+
+ private static Date truncateToSecondsImpl(Date d) {
+ Instant instant = d.toInstant();
+ instant = instant.truncatedTo(ChronoUnit.SECONDS);
+ return Date.from(instant);
+ }
+
}