-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added DurationUtility. Updated all duration-related code. Updated tests to mostly not break. Still need to address TODOs.
- Loading branch information
Bill Smith
committed
Aug 16, 2018
1 parent
c969919
commit 3d160aa
Showing
11 changed files
with
103 additions
and
23 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
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
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
39 changes: 39 additions & 0 deletions
39
backend/src/main/java/edu/internet2/tier/shibboleth/admin/util/DurationUtility.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,39 @@ | ||
| package edu.internet2.tier.shibboleth.admin.util; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
|
|
||
| import javax.xml.datatype.DatatypeConfigurationException; | ||
| import javax.xml.datatype.DatatypeFactory; | ||
| import javax.xml.datatype.Duration; | ||
| import java.util.Date; | ||
|
|
||
| /** | ||
| * @author Bill Smith (wsmith@unicon.net) | ||
| */ | ||
| public class DurationUtility { | ||
| private static final DatatypeFactory datatypeFactory; | ||
|
|
||
| static { | ||
| DatatypeFactory factory; | ||
| try { | ||
| factory = DatatypeFactory.newInstance(); | ||
| } catch (DatatypeConfigurationException e) { | ||
| factory = null; | ||
| } | ||
| datatypeFactory = factory; | ||
| } | ||
|
|
||
| public static Long toMillis(String xmlDuration) { | ||
| if (datatypeFactory == null) { | ||
| throw new RuntimeException("DatatypeFactory was never initialized!"); | ||
| } | ||
| if (StringUtils.isBlank(xmlDuration)) { | ||
| return 0L; | ||
| } | ||
| Duration duration = datatypeFactory.newDuration(xmlDuration); | ||
|
|
||
| Date zero = new Date(0); | ||
| duration.addTo(zero); // potentially can return undesired results for large xmlDurations | ||
| return zero.getTime(); | ||
| } | ||
| } |
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