Make toSecondsPrecision() more readable and improv performance

This commit is contained in:
Paul Schaub 2022-03-07 10:24:08 +01:00
parent 5b9e72d42c
commit 126cc9df70
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
1 changed files with 8 additions and 6 deletions

View File

@ -46,21 +46,23 @@ public final class DateUtil {
}
/**
* "Round" a date down to seconds precision.
* Floor a date down to seconds precision.
* @param date date
* @return rounded date
* @return floored date
*/
public static Date toSecondsPrecision(Date date) {
long seconds = date.getTime() / 1000;
return new Date(seconds * 1000);
long millis = date.getTime();
long seconds = millis / 1000;
long floored = seconds * 1000;
return new Date(floored);
}
/**
* Return the current date "rounded" to UTC precision.
* Return the current date "floored" to UTC precision.
*
* @return now
*/
public static Date now() {
return parseUTCDate(formatUTCDate(new Date()));
return toSecondsPrecision(new Date());
}
}