View Javadoc
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      private DateUtil() {
30      }
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 range 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 range) {
43          final double differenceInDays = (compareTo - date) / 1000.0 / 60.0 / 60.0 / 24.0;
44          return differenceInDays < range;
45      }
46  }