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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.context.test.concepts;
24 import java.io.Serializable;
25 import java.util.Calendar;
26 import java.util.Date;
27 import java.util.TimeZone;
32 * The Class TestContextDateItem.
35 public class TestContextDateItem implements Serializable {
36 private static final long serialVersionUID = -6984963129968805460L;
46 private int milliSecond;
51 public TestContextDateItem() {
52 this(new Date(System.currentTimeMillis()));
58 * @param dateValue the date value
60 public TestContextDateItem(final Date dateValue) {
61 if (dateValue != null) {
62 setDateValue(dateValue.getTime());
71 * @param time the time
73 public TestContextDateItem(final long time) {
78 * Gets the date value.
80 * @return the date value
82 public Date getDateValue() {
83 return new Date(time);
87 * Sets the date value.
89 * @param dateValue the date value
91 public void setDateValue(final Date dateValue) {
92 if (dateValue != null) {
93 setDateValue(dateValue.getTime());
98 * Sets the date value.
100 * @param dateValue the date value
102 public void setDateValue(final long dateValue) {
103 this.time = dateValue;
105 final Calendar calendar = Calendar.getInstance();
106 calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
107 calendar.setTimeInMillis(time);
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);