@Override protected long doReadDateTime() { return currentValue.asDateTime().getValue(); }
/** * Gets the value of the key if it is a BsonDateTime, or throws if not. * * @param key the key * @return the value of the key as a BsonDateTime * @throws org.bson.BsonInvalidOperationException if the document does not contain the key or the value is not of the expected type */ public BsonDateTime getDateTime(final Object key) { throwIfKeyAbsent(key); return get(key).asDateTime(); }
/** * If the document does not contain the given key, return the given default value. Otherwise, gets the value of the key as a * BsonDateTime. * * @param key the key * @param defaultValue the default value * @return the value of the key as a BsonDateTime * @throws org.bson.BsonInvalidOperationException if the document contains the key but the value is not of the expected type */ public BsonDateTime getDateTime(final Object key, final BsonDateTime defaultValue) { if (!containsKey(key)) { return defaultValue; } return get(key).asDateTime(); }
colValue = keyvalueforStruct.getValue().asDateTime().getValue(); break;
@Test public void withDate() { final Date date = new Date(); final ObjectId id = ObjectId.get(); final Jackson expected = ImmutableJackson.builder() .id(id) .prop1("prop1") .prop2("22") .date(new Date(date.getTime())) .build(); repository.insert(expected).getUnchecked(); check(collection.count()).is(1L); final Jackson actual = repository.findAll().fetchAll().getUnchecked().get(0); check(expected).is(actual); final BsonDocument doc = collection.find().first(); check(doc.keySet()).hasContentInAnyOrder("_id", "prop1", "prop2", "date", "uuid"); check(doc.get("date").asDateTime().getValue()).is(date.getTime()); check(doc.get("_id").asObjectId().getValue()).is(id); }
@Test public void dateCodec() throws IOException { TypeAdapter<Date> adapter = GsonCodecs.typeAdapterFromCodec(new DateCodec()); Date date = new Date(); BsonDocument doc = new BsonDocument(); BsonDocumentWriter writer = new BsonDocumentWriter(doc); writer.writeStartDocument(); writer.writeName("$date"); adapter.write(new BsonWriter(writer), date); writer.writeEndDocument(); check(doc.keySet()).hasSize(1); check(doc.get("$date").getBsonType()).is(BsonType.DATE_TIME); check(doc.get("$date").asDateTime().getValue()).is(date.getTime()); } }
return value.asBinary().getData(); case DATE_TIME: return new Date(value.asDateTime().getValue()); case SYMBOL: return value.asSymbol().getSymbol();
break; case DATE_TIME: writeDateTime(value.asDateTime().getValue()); break; case NULL:
return value.asBinary().getData(); case DATE_TIME: return new Date(value.asDateTime().getValue()); case SYMBOL: return value.asSymbol().getSymbol();
uri = URLUtils.removeTrailingSlashes(parentUrl) .concat("/") .concat("" + docId.asDateTime().getValue()) .concat("?") .concat(DOC_ID_TYPE_QPARAM_KEY)
private static BsonDateTime getIdAsDate(String id) throws IllegalArgumentException { BsonValue ret = JsonUtils.parse(id); if (ret.isDateTime()) { return ret.asDateTime(); } else if (ret.isInt32()) { return new BsonDateTime(0l + ret.asInt32().getValue()); } else if (ret.isInt64()) { return new BsonDateTime(ret.asInt64().getValue()); } else { throw new IllegalArgumentException("The id is not a valid number " + id); } }
return new LongBsonDateTime(value.asDateTime().getValue()); case DB_POINTER: { BsonDbPointer casted = value.asDBPointer();
return new LongBsonDateTime(value.asDateTime().getValue()); case DB_POINTER: { BsonDbPointer casted = value.asDBPointer();
Instant instant = Instant.ofEpochMilli(value.asDateTime().getValue()); LocalDateTime dateTime = LocalDateTime.ofInstant( instant,