Search in sources :

Example 6 with DateTimeType

use of org.eclipse.smarthome.core.library.types.DateTimeType in project smarthome by eclipse.

the class NtpOSGiTest method testDateTimeChannelTimeZoneUpdate.

@Test
@Ignore("https://github.com/eclipse/smarthome/issues/5224")
public void testDateTimeChannelTimeZoneUpdate() {
    Configuration configuration = new Configuration();
    configuration.put(NtpBindingConstants.PROPERTY_TIMEZONE, TEST_TIME_ZONE_ID);
    initialize(configuration, NtpBindingConstants.CHANNEL_DATE_TIME, ACCEPTED_ITEM_TYPE_DATE_TIME, null, null);
    String testItemState = getItemState(ACCEPTED_ITEM_TYPE_DATE_TIME).toString();
    assertFormat(testItemState, DateTimeType.DATE_PATTERN_WITH_TZ_AND_MS);
    ZonedDateTime timeZoneFromItemRegistry = ((DateTimeType) getItemState(ACCEPTED_ITEM_TYPE_DATE_TIME)).getZonedDateTime();
    ZoneOffset expectedOffset;
    if (timeZoneFromItemRegistry.getZone().getRules().isDaylightSavings(timeZoneFromItemRegistry.toInstant())) {
        expectedOffset = ZoneOffset.of("-07:00");
    } else {
        expectedOffset = ZoneOffset.of("-08:00");
    }
    assertEquals(expectedOffset, timeZoneFromItemRegistry.getOffset());
}
Also used : DateTimeType(org.eclipse.smarthome.core.library.types.DateTimeType) Configuration(org.eclipse.smarthome.config.core.Configuration) ZonedDateTime(java.time.ZonedDateTime) ZoneOffset(java.time.ZoneOffset) Ignore(org.junit.Ignore) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 7 with DateTimeType

use of org.eclipse.smarthome.core.library.types.DateTimeType in project smarthome by eclipse.

the class NtpOSGiTest method testDateTimeChannelDefaultTimeZoneUpdate.

@Test
public void testDateTimeChannelDefaultTimeZoneUpdate() {
    ZonedDateTime zoned = ZonedDateTime.now();
    ZoneOffset expectedTimeZone = zoned.getOffset();
    Configuration configuration = new Configuration();
    // Initialize with configuration with no time zone property set.
    initialize(configuration, NtpBindingConstants.CHANNEL_DATE_TIME, ACCEPTED_ITEM_TYPE_DATE_TIME, null, null);
    String testItemState = getItemState(ACCEPTED_ITEM_TYPE_DATE_TIME).toString();
    assertFormat(testItemState, DateTimeType.DATE_PATTERN_WITH_TZ_AND_MS);
    ZoneOffset timeZoneFromItemRegistry = new DateTimeType(testItemState).getZonedDateTime().getOffset();
    assertEquals(expectedTimeZone, timeZoneFromItemRegistry);
}
Also used : DateTimeType(org.eclipse.smarthome.core.library.types.DateTimeType) Configuration(org.eclipse.smarthome.config.core.Configuration) ZonedDateTime(java.time.ZonedDateTime) ZoneOffset(java.time.ZoneOffset) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 8 with DateTimeType

use of org.eclipse.smarthome.core.library.types.DateTimeType in project smarthome by eclipse.

the class DateTimeItemTest method testDateTimeType.

@Test
public void testDateTimeType() {
    DateTimeItem item = new DateTimeItem("test");
    DateTimeType state = new DateTimeType();
    item.setState(state);
    assertEquals(state, item.getState());
}
Also used : DateTimeType(org.eclipse.smarthome.core.library.types.DateTimeType) Test(org.junit.Test)

Example 9 with DateTimeType

use of org.eclipse.smarthome.core.library.types.DateTimeType in project smarthome by eclipse.

the class ItemUIRegistryImplTest method getLabel_labelWithTime.

@Test
public void getLabel_labelWithTime() throws ItemNotFoundException {
    String testLabel = "Label [%1$tT]";
    when(widget.getLabel()).thenReturn(testLabel);
    when(item.getState()).thenReturn(new DateTimeType("2011-06-01T15:30:59"));
    String label = uiRegistry.getLabel(widget);
    assertEquals("Label [15:30:59]", label);
}
Also used : DateTimeType(org.eclipse.smarthome.core.library.types.DateTimeType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 10 with DateTimeType

use of org.eclipse.smarthome.core.library.types.DateTimeType in project smarthome by eclipse.

the class ItemUIRegistryImplTest method getLabel_labelWithZonedTime.

@Test
public void getLabel_labelWithZonedTime() throws ItemNotFoundException {
    String testLabel = "Label [%1$tT]";
    Widget w = mock(Widget.class);
    Item item = mock(Item.class);
    when(w.getLabel()).thenReturn(testLabel);
    when(w.getItem()).thenReturn("Item");
    when(registry.getItem("Item")).thenReturn(item);
    when(item.getState()).thenReturn(new DateTimeType("2011-06-01T15:30:59Z"));
    String label = uiRegistry.getLabel(w);
    assertEquals("Label [15:30:59]", label);
}
Also used : ColorItem(org.eclipse.smarthome.core.library.items.ColorItem) Item(org.eclipse.smarthome.core.items.Item) DateTimeType(org.eclipse.smarthome.core.library.types.DateTimeType) Widget(org.eclipse.smarthome.model.sitemap.Widget) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

DateTimeType (org.eclipse.smarthome.core.library.types.DateTimeType)16 Test (org.junit.Test)10 ZonedDateTime (java.time.ZonedDateTime)7 State (org.eclipse.smarthome.core.types.State)6 ZoneOffset (java.time.ZoneOffset)4 Configuration (org.eclipse.smarthome.config.core.Configuration)4 StringType (org.eclipse.smarthome.core.library.types.StringType)4 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Ignore (org.junit.Ignore)3 Item (org.eclipse.smarthome.core.items.Item)2 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)2 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)2 Widget (org.eclipse.smarthome.model.sitemap.Widget)2 BigDecimal (java.math.BigDecimal)1 LinkedList (java.util.LinkedList)1 Temperature (javax.measure.quantity.Temperature)1 WeatherUndergroundJsonForecastDay (org.eclipse.smarthome.binding.weatherunderground.internal.json.WeatherUndergroundJsonForecastDay)1 HSBType (org.eclipse.smarthome.core.library.types.HSBType)1 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)1