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());
}
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);
}
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());
}
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);
}
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);
}
Aggregations