]> git.basschouten.com Git - openhab-addons.git/blob
4f23af308ad948b409433e74320c9b899286ed0a
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.sensorcommunity.internal.util;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import java.time.LocalDateTime;
18 import java.time.format.DateTimeParseException;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.sensorcommunity.internal.utils.DateTimeUtils;
23
24 /**
25  * The {@link DateTimeTest} Test DateTimeFormatter provided in utils package
26  *
27  * @author Bernd Weymann - Initial contribution
28  */
29 @NonNullByDefault
30 public class DateTimeTest {
31
32     @Test
33     public void testJSonTime() {
34         String jsonDateString = "2020-08-14 14:53:21";
35         try {
36             LocalDateTime dt = LocalDateTime.from(DateTimeUtils.DTF.parse(jsonDateString));
37             assertEquals(14, dt.getDayOfMonth(), "Day");
38             assertEquals(8, dt.getMonthValue(), "Month");
39             assertEquals(2020, dt.getYear(), "Year");
40
41             String s = dt.format(DateTimeUtils.DTF);
42             assertEquals(jsonDateString, s, "String");
43         } catch (DateTimeParseException e) {
44             assertFalse(true);
45         }
46     }
47 }