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;
31 * The Class TestContextDateItem.
34 public class TestContextDateItem implements Serializable {
35 private static final long serialVersionUID = -6984963129968805460L;
45 private int milliSecond;
50 public TestContextDateItem() {
51 this(new Date(System.currentTimeMillis()));
57 * @param dateValue the date value
59 public TestContextDateItem(final Date dateValue) {
60 if (dateValue != null) {
61 setDateValue(dateValue.getTime());
70 * @param time the time
72 public TestContextDateItem(final long time) {
77 * Gets the date value.
79 * @return the date value
81 public Date getDateValue() {
82 return new Date(time);
86 * Sets the date value.
88 * @param dateValue the date value
90 public void setDateValue(final Date dateValue) {
91 if (dateValue != null) {
92 setDateValue(dateValue.getTime());
97 * Sets the date value.
99 * @param dateValue the date value
101 public void setDateValue(final long dateValue) {
102 this.time = dateValue;
104 final Calendar calendar = Calendar.getInstance();
105 calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
106 calendar.setTimeInMillis(time);
108 year = calendar.get(Calendar.YEAR);
109 month = calendar.get(Calendar.MONTH);
110 day = calendar.get(Calendar.DAY_OF_MONTH);
111 hour = calendar.get(Calendar.HOUR);
112 minute = calendar.get(Calendar.MINUTE);
113 second = calendar.get(Calendar.SECOND);
114 milliSecond = calendar.get(Calendar.MILLISECOND);