mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-19 16:03:07 +00:00
Move DateMathParser from instance variables to locals, so "now" is current time not startup time.
Clamp access condition dates to midnight UTC. Add a lot of debug logging and a test main().
This commit is contained in:
42
dspace-api/src/main/java/org/dspace/util/TimeHelpers.java
Normal file
42
dspace-api/src/main/java/org/dspace/util/TimeHelpers.java
Normal file
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.util;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* Various manipulations of dates and times.
|
||||
*
|
||||
* @author mwood
|
||||
*/
|
||||
public class TimeHelpers {
|
||||
private static final TimeZone UTC = TimeZone.getTimeZone("UTC");
|
||||
|
||||
/**
|
||||
* Never instantiate this class.
|
||||
*/
|
||||
private TimeHelpers() {}
|
||||
|
||||
/**
|
||||
* Set a Date's time to midnight UTC.
|
||||
*
|
||||
* @param from some date-time.
|
||||
* @return midnight UTC of the supplied date-time.
|
||||
*/
|
||||
public static Date toMidnightUTC(Date from) {
|
||||
GregorianCalendar calendar = new GregorianCalendar(UTC);
|
||||
calendar.setTime(from);
|
||||
calendar.set(GregorianCalendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(GregorianCalendar.MINUTE, 0);
|
||||
calendar.set(GregorianCalendar.SECOND, 0);
|
||||
calendar.set(GregorianCalendar.MILLISECOND, 0);
|
||||
return calendar.getTime();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user