1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-26 22:32:07 +01:00

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

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 * @param date date
* @return rounded date * @return floored date
*/ */
public static Date toSecondsPrecision(Date date) { public static Date toSecondsPrecision(Date date) {
long seconds = date.getTime() / 1000; long millis = date.getTime();
return new Date(seconds * 1000); 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 * @return now
*/ */
public static Date now() { public static Date now() {
return parseUTCDate(formatUTCDate(new Date())); return toSecondsPrecision(new Date());
} }
} }