Coverage Report - org.owasp.dependencycheck.utils.DateUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
DateUtil
50%
2/4
100%
2/2
1
 
 1  
 /*
 2  
  * This file is part of dependency-check-core.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  *
 16  
  * Copyright (c) 2014 Jeremy Long. All Rights Reserved.
 17  
  */
 18  
 package org.owasp.dependencycheck.utils;
 19  
 
 20  
 /**
 21  
  *
 22  
  * @author Jeremy Long
 23  
  */
 24  
 public final class DateUtil {
 25  
 
 26  
     /**
 27  
      * Private constructor for utility class.
 28  
      */
 29  0
     private DateUtil() {
 30  0
     }
 31  
 
 32  
     /**
 33  
      * Determines if the epoch date is within the range specified of the compareTo epoch time. This takes the
 34  
      * (compareTo-date)/1000/60/60/24 to get the number of days. If the calculated days is less then the range the date
 35  
      * is considered valid.
 36  
      *
 37  
      * @param date the date to be checked.
 38  
      * @param compareTo the date to compare to.
 39  
      * @param dayRange the range in days to be considered valid.
 40  
      * @return whether or not the date is within the range.
 41  
      */
 42  
     public static boolean withinDateRange(long date, long compareTo, int dayRange) {
 43  
         // ms = dayRange x 24 hours/day x 60 min/hour x 60 sec/min x 1000 ms/sec
 44  9
         final long msRange = dayRange * 24L * 60L * 60L * 1000L;
 45  9
         return (compareTo - date) < msRange;
 46  
     }
 47  
 }