use of org.openhab.core.library.types.DateTimeType in project openhab1-addons by openhab.
the class AbstractDynamoDBItemSerializationTest method testDateTimeTypeLocalWithDateTimeItem.
@Test
public void testDateTimeTypeLocalWithDateTimeItem() throws IOException {
Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(TimeZone.getTimeZone("GMT+03:00"));
// GMT: Sun, 17 Jul 2016 16:38:07.050 GMT
calendar.setTimeInMillis(1468773487050L);
DynamoDBItem<?> dbitem = testStateGeneric(new DateTimeType(calendar), "2016-07-17T16:38:07.050Z");
// when deserializing data, we get the date in UTC Calendar
Calendar expectedCal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
expectedCal.setTimeInMillis(1468773487050L);
testAsHistoricGeneric(dbitem, new DateTimeItem("foo"), new DateTimeType(expectedCal));
}
use of org.openhab.core.library.types.DateTimeType in project openhab1-addons by openhab.
the class AbstractDynamoDBItemSerializationTest method testDateTimeTypeWithDateTimeItem.
@Test
public void testDateTimeTypeWithDateTimeItem() throws IOException {
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
calendar.set(2016, Calendar.MAY, 1, 13, 46, 0);
calendar.set(Calendar.MILLISECOND, 50);
DynamoDBItem<?> dbitem = testStateGeneric(new DateTimeType(calendar), "2016-05-01T13:46:00.050Z");
testAsHistoricGeneric(dbitem, new DateTimeItem("foo"), new DateTimeType(calendar));
}
use of org.openhab.core.library.types.DateTimeType in project openhab1-addons by openhab.
the class AbstractDynamoDBItemSerializationTest method testDateTimeTypeWithStringItem.
@Test
public void testDateTimeTypeWithStringItem() throws IOException {
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
calendar.set(2016, Calendar.MAY, 1, 13, 46, 0);
calendar.set(Calendar.MILLISECOND, 50);
DynamoDBItem<?> dbitem = testStateGeneric(new DateTimeType(calendar), "2016-05-01T13:46:00.050Z");
testAsHistoricGeneric(dbitem, new StringItem("foo"), new StringType("2016-05-01T13:46:00.050Z"));
}
use of org.openhab.core.library.types.DateTimeType in project openhab1-addons by openhab.
the class AbstractDynamoDBItemSerializationTest method testDateTimeTypeLocalWithStringItem.
@Test
public void testDateTimeTypeLocalWithStringItem() throws IOException {
Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(TimeZone.getTimeZone("GMT+03:00"));
// GMT: Sun, 17 Jul 2016 16:38:07.050 GMT
calendar.setTimeInMillis(1468773487050L);
DynamoDBItem<?> dbitem = testStateGeneric(new DateTimeType(calendar), "2016-07-17T16:38:07.050Z");
testAsHistoricGeneric(dbitem, new StringItem("foo"), new StringType("2016-07-17T16:38:07.050Z"));
}
use of org.openhab.core.library.types.DateTimeType in project openhab1-addons by openhab.
the class MongoDBPersistenceService method query.
@Override
public Iterable<HistoricItem> query(FilterCriteria filter) {
if (!initialized) {
return Collections.emptyList();
}
if (!isConnected()) {
connectToDatabase();
}
if (!isConnected()) {
return Collections.emptyList();
}
String name = filter.getItemName();
Item item = getItem(name);
List<HistoricItem> items = new ArrayList<HistoricItem>();
DBObject query = new BasicDBObject();
if (filter.getItemName() != null) {
query.put(FIELD_ITEM, filter.getItemName());
}
if (filter.getState() != null && filter.getOperator() != null) {
String op = convertOperator(filter.getOperator());
Object value = convertValue(filter.getState());
query.put(FIELD_VALUE, new BasicDBObject(op, value));
}
if (filter.getBeginDate() != null) {
query.put(FIELD_TIMESTAMP, new BasicDBObject("$gte", filter.getBeginDate()));
}
if (filter.getEndDate() != null) {
query.put(FIELD_TIMESTAMP, new BasicDBObject("$lte", filter.getEndDate()));
}
Integer sortDir = (filter.getOrdering() == Ordering.ASCENDING) ? 1 : -1;
DBCursor cursor = this.mongoCollection.find(query).sort(new BasicDBObject(FIELD_TIMESTAMP, sortDir)).skip(filter.getPageNumber() * filter.getPageSize()).limit(filter.getPageSize());
while (cursor.hasNext()) {
BasicDBObject obj = (BasicDBObject) cursor.next();
final State state;
if (item instanceof NumberItem) {
state = new DecimalType(obj.getDouble(FIELD_VALUE));
} else if (item instanceof DimmerItem) {
state = new PercentType(obj.getInt(FIELD_VALUE));
} else if (item instanceof SwitchItem) {
state = OnOffType.valueOf(obj.getString(FIELD_VALUE));
} else if (item instanceof ContactItem) {
state = OpenClosedType.valueOf(obj.getString(FIELD_VALUE));
} else if (item instanceof RollershutterItem) {
state = new PercentType(obj.getInt(FIELD_VALUE));
} else if (item instanceof ColorItem) {
state = new HSBType(obj.getString(FIELD_VALUE));
} else if (item instanceof DateTimeItem) {
Calendar cal = Calendar.getInstance();
cal.setTime(obj.getDate(FIELD_VALUE));
state = new DateTimeType(cal);
} else {
state = new StringType(obj.getString(FIELD_VALUE));
}
items.add(new MongoDBItem(name, state, obj.getDate(FIELD_TIMESTAMP)));
}
return items;
}
Aggregations