2 * Copyright 2017 BOCO Corporation. CMCC Technologies Co., Ltd
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onap.vfc.nfvo.emsdriver.commons.utils;
18 import java.util.Calendar;
19 import java.util.Date;
21 public class DateUtil {
24 public static long[] getScanScope(Date fireTime, long collectPeriod) {
25 Calendar fire = Calendar.getInstance();
28 fire.setTime(fireTime);
29 fire.set(Calendar.SECOND,0);
30 fire.set(Calendar.MILLISECOND, 0);
32 if (collectPeriod < 3600) {//minute
33 long minite = fire.get(Calendar.MINUTE);
34 long collectMinite = (int)collectPeriod/60;
35 long s = minite%collectMinite;
36 end = fire.getTimeInMillis() - s*60*1000;
37 start = end - collectPeriod * 1000;
38 }else if (collectPeriod == 3600) {
39 fire.set(Calendar.MINUTE, 0);
40 end = fire.getTimeInMillis();
41 start = end - collectPeriod * 1000;
42 }else if (collectPeriod == 24*60*60){ //day
43 fire.set(Calendar.HOUR_OF_DAY, 0);
44 fire.set(Calendar.MINUTE, 0);
45 end = fire.getTimeInMillis();
46 start = end - collectPeriod * 1000;
49 if (collectPeriod>0) {
50 end = fire.getTimeInMillis()-(fire.getTimeInMillis()+8*60*60*1000)%(collectPeriod*1000);
54 start = end - collectPeriod * 1000;
57 return new long[] {start,end};