2 * Copyright © 2019 IBM.
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.
17 package org.onap.ccsdk.cds.controllerblueprints.core.utils
19 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
20 import java.text.SimpleDateFormat
21 import java.time.LocalDateTime
22 import java.time.ZoneId
23 import java.time.format.DateTimeFormatter
26 fun controllerDate(): Date {
27 val localDateTime = LocalDateTime.now(ZoneId.systemDefault())
28 return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant())
31 fun currentTimestamp(): String {
32 val localDateTime = LocalDateTime.now(ZoneId.systemDefault())
33 val formatter = DateTimeFormatter.ofPattern(BluePrintConstants.DATE_TIME_PATTERN)
34 return formatter.format(localDateTime)
37 /** Parse string date in CDS string format */
38 fun String.toControllerDate(): Date {
39 val formatter = SimpleDateFormat(BluePrintConstants.DATE_TIME_PATTERN)
40 return formatter.parse(this)
43 /** Return date to CDS string format */
44 fun Date.currentTimestamp(): String {
45 val formatter = SimpleDateFormat(BluePrintConstants.DATE_TIME_PATTERN)
46 return formatter.format(this)