2 * Copyright (c) 2010-2021 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 {
34 private static final String NAME = "datetime";
35 private static final ZonedDateTime ZDT1 = ZonedDateTime.parse("2016-06-15T10:00:00Z");
36 private static final ZonedDateTime ZDT2 = ZonedDateTime.parse("2016-06-15T16:00:00.123Z");
37 private static final ZonedDateTime ZDT_BETWEEN = ZonedDateTime.parse("2016-06-15T14:00:00Z");
39 // State1 stored as DateTimeType wrapping ZonedDateTime specified in UTC
40 private static final DateTimeType STATE1 = new DateTimeType(ZDT1);
41 // State2 stored as DateTimeType wrapping ZonedDateTime specified in UTC+5
42 private static final DateTimeType STATE2 = new DateTimeType(ZDT2.withZoneSameInstant(ZoneOffset.ofHours(5)));
43 private static final DateTimeType STATE_BETWEEN = new DateTimeType(ZDT_BETWEEN);
46 public static void storeData() throws InterruptedException {
47 DateTimeItem item = (DateTimeItem) ITEMS.get(NAME);
49 item.setState(STATE1);
51 beforeStore = ZonedDateTime.now();
54 afterStore1 = ZonedDateTime.now();
56 item.setState(STATE2);
59 afterStore2 = ZonedDateTime.now();
61 LOGGER.info("Created item between {} and {}", AbstractDynamoDBItem.DATEFORMATTER.format(beforeStore),
62 AbstractDynamoDBItem.DATEFORMATTER.format(afterStore1));
66 protected String getItemName() {
71 protected State getFirstItemState() {
72 // The persistence converts to system default timezone
73 // Thus we need to convert here as well for comparison
75 // [main] TRACE org.openhab.persistence.dynamodb.internal.DynamoDBPersistenceService - Dynamo item datetime
76 // (Type=DateTimeItem, State=2016-06-15T16:00:00.123+0000, Label=null, Category=null) converted to historic
77 // item: datetime: 2020-11-28T11:29:54.326Z: 2016-06-15T19:00:00.123+0300
78 return STATE1.toZone(ZoneId.systemDefault());
82 protected State getSecondItemState() {
83 // The persistence converts to system default timezone
84 // Thus we need to convert here as well for comparison
86 // [main] TRACE org.openhab.persistence.dynamodb.internal.DynamoDBPersistenceService - Dynamo item datetime
87 // (Type=DateTimeItem, State=2016-06-15T16:00:00.123+0000, Label=null, Category=null) converted to historic
88 // item: datetime: 2020-11-28T11:29:54.326Z: 2016-06-15T19:00:00.123+0300
89 return STATE2.toZone(ZoneId.systemDefault());
93 protected @Nullable State getQueryItemStateBetween() {