Revert changes to getStartOfDay.

Sonar suggested using the Java 8 method Instant.truncatedTo, as it is faster than
DateUtils.truncate. However it has different handling of TimeZones, and the old
version of this code only works when the server is set to use UTC. In order to fix
this 'properly' we need code like:
  date = (date == null ? new Date() : date);
  return Date.from(date.toInstant().atZone(ZoneId.systemDefault()).truncatedTo(ChronoUnit.DAYS).toInstant());
which is significantly less readable than just using DateUtils.truncate. Given that
this code hasn't ever been highlighted by our profiling, I suggest we revert back
to the older code.
This commit is contained in:
Tom Page
2018-01-18 16:13:20 +01:00
parent 398f8079fe
commit 0a54487bcf

View File

@@ -37,7 +37,6 @@ import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Serializable;
import java.io.Writer;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
@@ -1140,8 +1139,7 @@ public class RecordsManagementAuditServiceImpl extends AbstractLifecycleBean
*/
protected Date getStartOfDay(Date date)
{
date = (date == null ? new Date() : date);
return Date.from(date.toInstant().truncatedTo(ChronoUnit.DAYS));
return DateUtils.truncate(date == null ? new Date() : date, Calendar.DATE);
}
/**