Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8698 from mwoodiupui/embargo-date
Calculate the correct maximum for access condition start and end dates
- Loading branch information
Showing
8 changed files
with
212 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
dspace-api/src/test/java/org/dspace/util/TimeHelpersTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* 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 static org.junit.Assert.assertEquals; | ||
|
||
import java.time.ZoneOffset; | ||
import java.time.ZonedDateTime; | ||
import java.util.Date; | ||
|
||
import org.junit.Test; | ||
|
||
/** | ||
* Test {@link TimeHelpers}. | ||
* @author Mark H. Wood <mwood@iupui.edu> | ||
*/ | ||
public class TimeHelpersTest { | ||
/** | ||
* Test of toMidnightUTC method, of class TimeHelpers. | ||
*/ | ||
@Test | ||
public void testToMidnightUTC() { | ||
System.out.println("toMidnightUTC"); | ||
Date from = Date.from(ZonedDateTime.of(1957, 01, 27, 04, 05, 06, 007, ZoneOffset.UTC).toInstant()); | ||
Date expResult = Date.from(ZonedDateTime.of(1957, 01, 27, 00, 00, 00, 000, ZoneOffset.UTC).toInstant()); | ||
Date result = TimeHelpers.toMidnightUTC(from); | ||
assertEquals(expResult, result); | ||
} | ||
} |
Oops, something went wrong.