@Override public BsonDateTime decode(final BsonReader reader, final DecoderContext decoderContext) { return new BsonDateTime(reader.readDateTime()); }
@Override protected long doReadDateTime() { return currentValue.asDateTime().getValue(); }
.getDateTime(UpdateOneTimestampsStrategy.FIELDNAME_INSERTED_TS); assertTrue(insertedTS.equals(modifiedTS), () -> "modified and inserted timestamps must initially be equal");
@Override public void encode(final BsonWriter writer, final BsonDateTime value, final EncoderContext encoderContext) { writer.writeDateTime(value.getValue()); }
@Override protected void doWriteDateTime(final long value) { write(new BsonDateTime(value)); }
private static Date getLastWriteDate(final BsonDocument isMasterResult) { if (!isMasterResult.containsKey("lastWrite")) { return null; } return new Date(isMasterResult.getDocument("lastWrite").getDateTime("lastWriteDate").getValue()); }
@Override @SuppressWarnings("deprecation") public void encode(final BsonWriter writer, final GridFSFile value, final EncoderContext encoderContext) { BsonDocument bsonDocument = new BsonDocument(); bsonDocument.put("_id", value.getId()); bsonDocument.put("filename", new BsonString(value.getFilename())); bsonDocument.put("length", new BsonInt64(value.getLength())); bsonDocument.put("chunkSize", new BsonInt32(value.getChunkSize())); bsonDocument.put("uploadDate", new BsonDateTime(value.getUploadDate().getTime())); if (value.getMD5() != null) { bsonDocument.put("md5", new BsonString(value.getMD5())); } Document metadata = value.getMetadata(); if (metadata != null) { bsonDocument.put("metadata", new BsonDocumentWrapper<Document>(metadata, documentCodec)); } Document extraElements = value.getExtraElements(); if (extraElements != null) { bsonDocument.putAll(new BsonDocumentWrapper<Document>(extraElements, documentCodec)); } bsonDocumentCodec.encode(writer, bsonDocument, encoderContext); }
colValue = keyvalueforStruct.getValue().asDateTime().getValue(); break;
@Override public BsonValue toBson(Object data) { return new BsonDateTime(((java.util.Date)data).getTime()); } }
@Override public GridFSFile decode(final BsonReader reader, final DecoderContext decoderContext) { BsonDocument bsonDocument = bsonDocumentCodec.decode(reader, decoderContext); BsonValue id = bsonDocument.get("_id"); String filename = bsonDocument.get("filename", new BsonString("")).asString().getValue(); long length = bsonDocument.getNumber("length").longValue(); int chunkSize = bsonDocument.getNumber("chunkSize").intValue(); Date uploadDate = new Date(bsonDocument.getDateTime("uploadDate").getValue()); String md5 = bsonDocument.containsKey("md5") ? bsonDocument.getString("md5").getValue() : null; BsonDocument metadataBsonDocument = bsonDocument.getDocument("metadata", new BsonDocument()); Document optionalMetadata = asDocumentOrNull(metadataBsonDocument); for (String key : VALID_FIELDS) { bsonDocument.remove(key); } Document deprecatedExtraElements = asDocumentOrNull(bsonDocument); return new GridFSFile(id, filename, length, chunkSize, uploadDate, md5, optionalMetadata, deprecatedExtraElements); }
@Override public BsonValue toBson(Object data) { return new BsonDateTime(((java.util.Date)data).getTime()); } }
@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); }
@Override public BsonValue toBson(Object data) { return new BsonDateTime(((java.util.Date)data).getTime()); } }
@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()); } }
@Override public BsonValue toBson(Object data) { return new BsonDateTime(((java.util.Date)data).getTime()); } }
return value.asBinary().getData(); case DATE_TIME: return new Date(value.asDateTime().getValue()); case SYMBOL: return value.asSymbol().getSymbol();
@Override public BsonValue toBson(Object data) { return new BsonDateTime(((java.util.Date)data).getTime()); } }
break; case DATE_TIME: writeDateTime(value.asDateTime().getValue()); break; case NULL:
@Override public BsonValue toBson(Object data) { return new BsonDateTime(((java.util.Date)data).getTime()); } }
private static Date localTimeFrom(ServerHeartbeatSucceededEvent event) { BsonDocument reply = event.getReply(); return new Date(reply.getDateTime("localTime").getValue()); }