b35b061a7783a61b3f9f3d76f7d0de376f68a98a
[policy/apex-pdp.git] / testsuites / integration / integration-common / src / main / java / org / onap / policy / apex / context / test / concepts / TestContextDateItem.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2019-2020 Nordix Foundation.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.context.test.concepts;
23
24 import java.io.Serializable;
25 import java.util.Calendar;
26 import java.util.Date;
27 import java.util.TimeZone;
28
29 import lombok.Data;
30
31 /**
32  * The Class TestContextDateItem.
33  */
34 @Data
35 public class TestContextDateItem implements Serializable {
36     private static final long serialVersionUID = -6984963129968805460L;
37
38     private long time;
39
40     private int year;
41     private int month;
42     private int day;
43     private int hour;
44     private int minute;
45     private int second;
46     private int milliSecond;
47
48     /**
49      * The Constructor.
50      */
51     public TestContextDateItem() {
52         this(new Date(System.currentTimeMillis()));
53     }
54
55     /**
56      * The Constructor.
57      *
58      * @param dateValue the date value
59      */
60     public TestContextDateItem(final Date dateValue) {
61         if (dateValue != null) {
62             setDateValue(dateValue.getTime());
63         } else {
64             new Date(0);
65         }
66     }
67
68     /**
69      * The Constructor.
70      *
71      * @param time the time
72      */
73     public TestContextDateItem(final long time) {
74         setDateValue(time);
75     }
76
77     /**
78      * Gets the date value.
79      *
80      * @return the date value
81      */
82     public Date getDateValue() {
83         return new Date(time);
84     }
85
86     /**
87      * Sets the date value.
88      *
89      * @param dateValue the date value
90      */
91     public void setDateValue(final Date dateValue) {
92         if (dateValue != null) {
93             setDateValue(dateValue.getTime());
94         }
95     }
96
97     /**
98      * Sets the date value.
99      *
100      * @param dateValue the date value
101      */
102     public void setDateValue(final long dateValue) {
103         this.time = dateValue;
104
105         final Calendar calendar = Calendar.getInstance();
106         calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
107         calendar.setTimeInMillis(time);
108
109         year = calendar.get(Calendar.YEAR);
110         month = calendar.get(Calendar.MONTH);
111         day = calendar.get(Calendar.DAY_OF_MONTH);
112         hour = calendar.get(Calendar.HOUR);
113         minute = calendar.get(Calendar.MINUTE);
114         second = calendar.get(Calendar.SECOND);
115         milliSecond = calendar.get(Calendar.MILLISECOND);
116     }
117 }