2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.enturno.internal.util;
15 import java.time.ZonedDateTime;
16 import java.time.format.DateTimeFormatter;
17 import java.time.format.DateTimeParseException;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
22 * EnturNo date utility methods.
24 * @author Jacob Laursen - Initial contribution
27 public class DateUtil {
29 * Converts a zoned date time string that lacks a colon in the zone to an ISO-8601 formatted string.
31 * @param dateTimeWithoutColonInZone
32 * @return ISO-8601 formatted string
34 public static String getIsoDateTime(String dateTimeWithoutColonInZone) {
35 ZonedDateTime zonedDateTime = null;
37 zonedDateTime = ZonedDateTime.parse(dateTimeWithoutColonInZone);
38 } catch (DateTimeParseException e) {
42 zonedDateTime = ZonedDateTime.parse(dateTimeWithoutColonInZone.replaceAll("(\\d{2})(\\d{2})$", "$1:$2"));
43 } catch (DateTimeParseException e) {
46 if (zonedDateTime != null) {
47 return DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(zonedDateTime);
49 return dateTimeWithoutColonInZone;