c0fddad2be3a4b13b694aa15c15c6762345e5e59
[vfc/nfvo/driver/ems.git] / ems / boco / src / main / java / org / onap / vfc / nfvo / emsdriver / commons / utils / DateUtil.java
1 /**
2  * Copyright 2017 BOCO Corporation.  CMCC Technologies Co., Ltd
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 package org.onap.vfc.nfvo.emsdriver.commons.utils;
17
18 import java.util.Calendar;
19 import java.util.Date;
20
21 public class DateUtil {
22         
23         
24         public static long[] getScanScope(Date fireTime, long collectPeriod) {
25                 Calendar fire = Calendar.getInstance();
26                 long start = 0L;
27                 long end = 0L;
28                 fire.setTime(fireTime);
29                 fire.set(Calendar.SECOND,0);
30                 fire.set(Calendar.MILLISECOND, 0);
31                 
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;
47                 }else{
48                         
49                         if (collectPeriod>0) { 
50                                 end = fire.getTimeInMillis()-(fire.getTimeInMillis()+8*60*60*1000)%(collectPeriod*1000);
51                         }else {
52                                 return null;
53                         }
54                         start = end - collectPeriod * 1000;
55                 }
56                 
57                 return new long[] {start,end};
58         }
59
60 }