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.persistence.dynamodb.internal;
15 import java.time.ZoneId;
16 import java.time.ZoneOffset;
17 import java.time.ZonedDateTime;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.junit.jupiter.api.BeforeAll;
22 import org.openhab.core.library.items.DateTimeItem;
23 import org.openhab.core.library.types.DateTimeType;
24 import org.openhab.core.types.State;
28 * @author Sami Salonen - Initial contribution
32 public class DateTimeItemIntegrationTest extends AbstractTwoItemIntegrationTest {
33 public static final boolean LEGACY_MODE = false;
35 private static final String NAME = "datetime";
36 private static final ZonedDateTime ZDT1 = ZonedDateTime.parse("2016-06-15T10:00:00Z");
37 private static final ZonedDateTime ZDT2 = ZonedDateTime.parse("2016-06-15T16:00:00.123Z");
38 private static final ZonedDateTime ZDT_BETWEEN = ZonedDateTime.parse("2016-06-15T14:00:00Z");
40 // State1 stored as DateTimeType wrapping ZonedDateTime specified in UTC
41 private static final DateTimeType STATE1 = new DateTimeType(ZDT1);
42 // State2 stored as DateTimeType wrapping ZonedDateTime specified in UTC+5
43 private static final DateTimeType STATE2 = new DateTimeType(ZDT2.withZoneSameInstant(ZoneOffset.ofHours(5)));
44 private static final DateTimeType STATE_BETWEEN = new DateTimeType(ZDT_BETWEEN);
46 @SuppressWarnings("null")
48 public static void storeData() throws InterruptedException {
49 DateTimeItem item = (DateTimeItem) ITEMS.get(NAME);
51 item.setState(STATE1);
53 beforeStore = ZonedDateTime.now();
56 afterStore1 = ZonedDateTime.now();
58 item.setState(STATE2);
61 afterStore2 = ZonedDateTime.now();
62 LOGGER.info("Created item between {} and {}", AbstractDynamoDBItem.DATEFORMATTER.format(beforeStore),
63 AbstractDynamoDBItem.DATEFORMATTER.format(afterStore1));
67 protected String getItemName() {
72 protected State getFirstItemState() {
73 // The persistence converts to system default timezone
74 // Thus we need to convert here as well for comparison
76 // [main] TRACE org.openhab.persistence.dynamodb.internal.DynamoDBPersistenceService - Dynamo item datetime
77 // (Type=DateTimeItem, State=2016-06-15T16:00:00.123+0000, Label=null, Category=null) converted to historic
78 // item: datetime: 2020-11-28T11:29:54.326Z: 2016-06-15T19:00:00.123+0300
79 return STATE1.toZone(ZoneId.systemDefault());
83 protected State getSecondItemState() {
84 // The persistence converts to system default timezone
85 // Thus we need to convert here as well for comparison
87 // [main] TRACE org.openhab.persistence.dynamodb.internal.DynamoDBPersistenceService - Dynamo item datetime
88 // (Type=DateTimeItem, State=2016-06-15T16:00:00.123+0000, Label=null, Category=null) converted to historic
89 // item: datetime: 2020-11-28T11:29:54.326Z: 2016-06-15T19:00:00.123+0300
90 return STATE2.toZone(ZoneId.systemDefault());
94 protected @Nullable State getQueryItemStateBetween() {