Package org.owasp.dependencycheck.utils
Class DateUtil
- java.lang.Object
-
- org.owasp.dependencycheck.utils.DateUtil
-
@ThreadSafe public final class DateUtil extends java.lang.Object
- Author:
- Jeremy Long
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static long
getEpochValueInSeconds(java.lang.String epoch)
Returns the string value converted to an epoch seconds.static java.util.Calendar
parseXmlDate(java.lang.String xsDate)
Parses an XML xs:date into a calendar object.static boolean
withinDateRange(long date, long compareTo, int dayRange)
Determines if the epoch date is within the range specified of the compareTo epoch time.static boolean
withinDateRange(java.time.ZonedDateTime date, java.time.ZonedDateTime compareTo, int dayRange)
Determines if the date is within the given day range.
-
-
-
Method Detail
-
parseXmlDate
public static java.util.Calendar parseXmlDate(java.lang.String xsDate) throws ParseException
Parses an XML xs:date into a calendar object.- Parameters:
xsDate
- an xs:date string- Returns:
- a calendar object
- Throws:
ParseException
- thrown if the date cannot be converted to a calendar
-
withinDateRange
public static boolean withinDateRange(long date, long compareTo, int dayRange)
Determines if the epoch date is within the range specified of the compareTo epoch time. This takes the (compareTo-date)/1000/60/60/24 to get the number of days. If the calculated days is less then the range the date is considered valid.- Parameters:
date
- the date to be checked.compareTo
- the date to compare to.dayRange
- the range in days to be considered valid.- Returns:
- whether or not the date is within the range.
-
withinDateRange
public static boolean withinDateRange(java.time.ZonedDateTime date, java.time.ZonedDateTime compareTo, int dayRange)
Determines if the date is within the given day range.- Parameters:
date
- the datecompareTo
- the date to compare againstdayRange
- the number of days allowed- Returns:
- if the date is within the dayRange of compareTo
-
getEpochValueInSeconds
public static long getEpochValueInSeconds(java.lang.String epoch)
Returns the string value converted to an epoch seconds. Note, in some cases the value provided may be in milliseconds.- Parameters:
epoch
- the property value- Returns:
- the value in seconds
-
-