mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-23 12:52:07 +01:00
Make toSecondsPrecision() more readable and improv performance
This commit is contained in:
parent
5b9e72d42c
commit
126cc9df70
1 changed files with 8 additions and 6 deletions
|
@ -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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue